Understanding the namespace assists the network administrator with judiciously applying WMI scripting to his or her network duties. However, as mentioned earlier, to access information through WMI, you must have access to a WMI provider. After the provider is implemented, you can gain access to the information that is made available. Two Excel spreadsheets with all the providers and their associated classes from Windows XP and from Windows Server 2003 are in the Supplemental Material folder on the CD-ROM. If you want to know which classes are supported by the RouteProvider, you can click the Filter button and select RouteProvider. This is shown in Figure 5-2.
Figure 5-2: The WMIProvidersXP.xls spreadsheet lists classes supported by provider name
Providers in WMI are all based on a template class, or a system class called __provider. Armed with this information, we can look for instances of the __provider class, and we will have a list of all the providers that reside in our WMI namespace. This is exactly what the ListWmiProviders.ps1 script does.
The ListWmiProviders.ps1 script begins by assigning the string Root\cimv2 to the $wmiNS variable. This value will be used with the Get-WmiObject cmdlet to specify where the WMI query will take place. Note that the WMI namespace Root\cimv2 is the default WMI namespace on Windows 2000, Windows XP, Windows Vista, and Windows Server 2003.
The Get-WmiObject cmdlet is used to query WMI. The class provider is used to limit the WMI query to the __provider class. The namespace argument tells the Get-WmiObject cmdlet to only look in the Root\cimv2 WMI namespace. The array of objects returned from the Get-WmiObject cmdlet is pipelined into the Sort-Object cmdlet, where the listing of objects is alphabetized based on the name property. After this process is completed, the reorganized objects are passed to the Format-List cmdlet, where the name of each provider is printed out.
ListWmiProviders.ps1
$wmiNS = "root\cimV2" Get-WmiObject -class __Provider -namespace $wmiNS | Sort-Object -property Name | Format-List name