The Scripting Guys at Microsoft have created an amazingly vital and under-advertised PowerShell script that lets you interactively explore the WMI.
Download it here
Then copy it somewhere convenient.
Then run it from your PowerShell prompt: ./WMIExplorer.ps1
Now, you probably want to start by double clicking ROOT\CIMV2, the best stuff is in there.
WMI classes are typcially collections. Of the members of these collections, you typcially only want to work with one.
Calling Get-WMIObject $className will give you every bit of information about every one of them.
To explore in a cleaner manner, add the following two functions to your PowerShell profile. This function will get just the names of the collection members. Use it to decide which collection member you would like to work with.
function List-WMI( [string] $class )
{
$strComputer = "."
$items = get-wmiobject -class $class -namespace "root\cimv2" -computername $strComputer
foreach ($objItem in $items) {
write-host $objItem.Name
}
}
Usage example:
List-WMI('Win32_Desktop')
or
List-WMI 'Win32_NetworkAdapter'
Next, you can use this function to grab just the item from the collection that you want.
function Get-WMI-Named( [string] $class, [string] $name )
{
return get-wmiobject -class $class -filter "Name='$name'"
}
Usage example:
Get-WMI-Named('Win32_Desktop', 'Edward')
Now use the Get-Member function to learn what methods and properties the object you’re examining has.
Get-WMI-Named('Win32_Desktop', 'Edward') | Get-Member
Here’s a quick command that uses the WMI class Win32_NetworkAdapter to list all your existing network connections.
Get-WMIObject Win32_NetworkAdapter | Format-List Name, MACAddress, AdapterType | less
It can be shortened using aliases for Get-WMIObject and Format-List
gwmi Win32_NetworkAdapter | fl Name, MACAddress, AdapterType | less
Looks easy now that you’ve seen it, right?
If you find that the Win32_NetworkAdapter class can’t do what you need; have a look at the Win32_NetworkAdapterConfiguration class.
Enjoy!