In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Windows PowerShell scripts in WMI use methods, for this problem, this article details the corresponding analysis and solutions, hoping to help more small partners who want to solve this problem to find a simpler and easier way.
Windows Management Instrumentation (WMI) is one of the tools that can transform your daily life. Although it has existed since the early 1990s, its popularity has been slow due to the complexity of WMI. Windows PowerShell breaks down this barrier, it makes WMI easier to use, and it changes the face of the IT industry.
Before we dive into how PowerShell simplifies WMI, let's take a look at what WMI is. This is the simplest term, you can think of WMI as a database full of queries that provide consistent and reliable data in a variety of formats.
Wikipedia explains that WMI aims to "specify a standard, non-proprietary setting for an independent environment that allows administrative information to be shared between administrative applications." "This is a fairly abstract explanation, and WMI may have started to try to be 'environment independent' now that things have changed, start thinking about what WMI will look like these days. When you hear about WMI today, it's usually used in Microsoft's WMI implementation environment through a built-in provider. That's what this article will focus on.
WMI consists of three basic elements:
Provider --Approves Access Management objects and provides valid WMI APIs
Classes --WMI statements for objects with properties and methods
Namespace --logical grouping of classes
So how does PowerShell make WMI easier to access?
First, let's look at the tools PowerShell provides for WMI. Overall there are 5 PowerShell command sets, which make WMI easy to use. I'll list them all here, but I'll focus on just one (Get-WMIObject):
Get-WmiObject--Returns objects based on namespaces and provided categories
Invoke-WmiMethod--invoke WMI programs (usually used to execute static programs)
Register-WmiEvent--Used to subscribe to WMI events
Remove-WmiObject --deletes an existing instance of a WMI class (to be clear, it does not actually delete the class itself, but rather an instance of the class in memory)
Set-WmiInstance --Create or update an instance of an existing WMI class (use it with caution because it actually writes to the WMI library)
Now let's solve the problem of *** in WMI, figure out what it is and what data it can provide.
You can rely on the following code to write programs:
$Root = "\\.\ ROOT:__namespace"$WMIProv = New-Object System.Management.ManagementClass ($Root)$WMIProv.GetInstances() | Select Name
(This is more complicated than other tasks.) Fortunately, you don't have to do this very often.)
Here's how you can provide classes by listing them in a specific namespace (Root\CIM2 by default, which includes all Microsoft Win32 classes):
# On local machineGet-WmiObject –Namespace Root\SecurityCenter –List# On Remote machineGet-WmiObject –Namespace Root\SecurityCenter –List –Computer core# To filter you can use wildcardsGet-WmiObject –Namespace Root\SecurityCenter –List *firewall*# To list the classes for HyperV on remote serverGet-WmiObject –Namespace Root\Virtualization –List –Computer core
(It's tough, but you can cheat with free tools like WMI or Microsoft PowerShell Scriptural.)
Now it's time to sit down and learn what's unusual about Get-WMI Object, which is the most useful of the five command sets. With it in your toolbox, you're a hair's breadth away from almost any piece of data you can think of (Microsoft-related systems). There are more than 600 Win32 classes that display CPU, memory, disk, process, network, BIOS, and USB information. Excited? Wait a minute and you'll see how easy it is.
Get operating system information:
Get-WmiObject –class win32_OperatingSystem
Get information about computer systems
Get-WmiObject –class win32_ComputerSystem
Get disk information:
Get-WmiObject –class Win32_LogicalDisk
Get network information:
Get-WmiObject –class Win32_NetworkAdapterConfiguration
Just try it-it's that simple.
Let's look at an example of using WMI to get IP information. The following valid script replaces ipconfig and its usual awful output.
function Get-IP{[Cmdletbinding()]Param([alias('dnsHostName')][Parameter(ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true) [string]$ComputerName = $Env:COMPUTERNAME)process{$NICs = Get-WmiObjectWin32_NetworkAdapterConfiguration -Filter"IPEnabled='$True'" -ComputerName $ComputerNameforeach ($Nic in $NICs){$myobj = @{Name = $Nic.DescriptionMacAddress = $Nic.MACAddressIP4 = $Nic.IPAddress | where{$_-match"\d+\.\ d+\.\ d+\.\ d+"}IP6 = $Nic.IPAddress | where{$_-match "\:\:"}IP4Subnet = $Nic.IPSubnet | where{$_-match"\d+\.\ d+\.\ d+\.\ d+"}DefaultGWY = $Nic.DefaultIPGateway |Select -First 1DNSServer = $Nic.DNSServerSearchOrderWINSPrimary = $Nic.WINSPrimaryServerWINSSecondary = $Nic.WINSSecondaryServer}$obj = New-Object PSObject -Property $myobj$obj.PSTypeNames.Clear()$obj.PSTypeNames.Add('BSonPosh.IPInfo')$obj}}}
You can find more information about WMI on Microsoft's website, as well as a list of WMI terms and Win32 classes.
About WMI Windows PowerShell script use method of the answer to share here, I hope the above content can have some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.