Automating the world one-liner at a time…
Both PowerShell and Windows Management Instrumentation (WMI) are pretty incredible technologies that can do a lot of amazing things, but we're all human, and keeping an encyclopedic mental reference of all of these amazing things would give Good Will Hunting a headache. For years, when I used WMI I almost always had a browser open to MSDN to help me figure out and remember the little details of a class in WMI, and, for all of the desktop clutter, it never bothered me... until I started using Powershell and had Get-Help and Get-Command.
These two cmdlets rocked my world. Get-Command could tell me all of the commands in a system, and the properties they accepted. Get-Help told me what the cmdlet did, and how to use it. All of a sudden I had the kinds of information I was always looking up online right at my fingertips... but not for WMI.
Luckily, it turns out that WMI actually has a way to provide help information. If you run Get-WmiObject, you can see what I mean:
Get-WmiObject __Namespace | Format-Table Name
This lists the namespaces underneath root\cimv2. You should have at least one namespace named something like ms_### . This namespace contains localized class help for the WMI classes in the parent namespace.
This means that no matter where in the world you are, you can get help from WMI in your language without connecting to the internet.
I wrote a few functions to make this feature of WMI a lot easier to access.
Get-WmiHelp: Gets you a dictionary with the help for a specific WMI classSearch-WmiHelp: Searches through the namespace for classes that match certain filters
Here are some examples:
Get-WmiHelp Win32_Process
Name Value---- -----Description The Win32_Process class represents a sequence...Properties {QuotaPeakPagedPoolUsage, CSCreationClassName...Methods {Terminate, AttachDebugger, Create, GetOwner...}
(Get-WmiHelp Win32_Bios).Description
The Win32_BIOS class represents the attributes of the computer system's basic input/output services (BIOS) that are installed on the computer.
(Get-WmiHelp Win32_Process).Methods.Create
The Create method creates a new process.The method returns an integer value that can be interpretted as follows:0 - Successful completion.2 - The user does not have access to the requested information.3 - The user does not have sufficient privilge.8 - Unknown failure.9 - The path specified does not exist.21 - The specified parameter is invalid.Other - For integer values other than those listed above, refer to Win32 error code documentation.
(Get-WmiHelp Win32_Volume).Properties.StatusInfo
StatusInfo is a string indicating whether the logical device is in an enabled (value = 3), disabled (value = 4) or some other (1) or unknown (2) state. If this property does not apply to the logical device, the value, 5 ("Not Applicable"), should be used.
Search-WmiHelp {$_ -like "*Disk*"} # Finds all classes whose description contains "Disk"
Name Value---- -----Win32_OperatingSystemAutoch... {Description, Properties, Methods}Win32_Volume {Description, Properties, Methods}....
Search-WmiHelp -Method {$_.Key -like "*Create*} # Finds all classes that contain a method named create
Name Value---- -----Win32_Service {Description, Properties, Methods}Win32_BaseService {Description, Properties, Methods}Win32_TerminalService {Description, Properties, Methods}Win32_Share {Description, Properties, Methods}
...
Search-WmiHelp -Property {$_.Value -like "*Quota*} # Finds all classes that contain a property whose description contains "Quota"
Name Value---- -----Win32_QuotaSetting {Description, Properties, Methods}Win32_LogicalDisk {Description, Properties, Methods}Win32_VolumeQuota {Description, Properties, Methods}Win32_VolumeUserQuota {Description, Properties, Methods}Win32_Process {Description, Properties, Methods}Win32_MappedLogicalDisk {Description, Properties, Methods}Win32_Volume {Description, Properties, Methods}Win32_VolumeQuotaSetting {Description, Properties, Methods}Win32_DiskQuota {Description, Properties, Methods}
Hope this helps,
James Brundage [MSFT]
---
Update: I have added a -Culture option to Get-WmiHelp and Search-WmiHelp. If Search-WmiHelp is giving you an "Invalid Namespace" error, then run:
Get-WmiObject "__Namespace" | Format-List Name and try passing the value of any ms_### namespace to Get-WmiHelp/Search-WmiHelp
e.g. Get-WmiHelp Win32_Process -culture 0xc0a:
Name Value---- -----Description La clase Win32_Process representa una secuenc...Properties {QuotaPeakPagedPoolUsage, CSCreationClassName...Methods {Terminate, AttachDebugger, Create, GetOwner...}
PingBack from http://www.artofbam.com/wordpress/?p=2630
I get the following error when I run Search-WmiHelp:
Get-WmiObject : Invalid namespace At D:\Documents\WindowsPowerShell\Add-WmiHelpFunctions.ps1:120 char:42
+ $localizedClasses = Get-WmiObject <<<< -NameSpace $localizedNamespace -Query "select * f
rom meta_class"
Attempted to divide by zero.
At D:\Documents\WindowsPowerShell\Add-WmiHelpFunctions.ps1:125 char:109
+ Write-Progress "Searching Wmi Classes" "$count of $($localizedClasses.Count)" -Perc (
$count*100/$ <<<< localizedClasses.Count)
And when I run Get-WmiHelp it just produces nothing. I'm running Vista, but I don't suppose that should make any difference.
Yup -- this stuff dont work :(
If you are having issues, please post the command line you ran Search-WmiHelp or Get-WmiHelp with, and the results of the following script:
Get-WmiObject -query "SELECT * FROM __Namespace" -namepsace (value of $namespace you passed to Get-WmiHelp (or blank))
Get-LocalalizedNamespace (value of $namespace you passed to Get-WmiHelp (or "root\Cimv2"))
This script mines the information from WMI, which is in a very standardized format (the description qualifier on each method/property/class in the localized namespace contains the help). One possibility is that the namespace does not exist on your box. Another possibility is that the namespace that one of the functions Get-WmiHelp and Search-WmiHelp both call (Get-LocalizedNamespace) is returning a bad namespace name.
I hope I can help identify why this script is not working for you.
Doesn't work here, either. I have an english language OS with German regional settings. (Get-culture).LCID returns 1031 (0x407). WMI only has namespace ms_0409. get-localizednamespace returns "ms_7f" in that case.
(warning, I'm a newbie). I get an error just trying to dot-source the script:
Unrecognized token in source text
(my path)\Add-WmiHelpFunctions.ps1:3 char:1 + @ <<<<
(Running Vista Business, 32-bit English)
Here's a result - and what fails. Platform is WinXP SP2 English / no localization.
------------------------------------
PS C:\> Get-WmiHelp Win32_Process
PS C:\> (Get-WmiHelp Win32_Bios).Description
PS C:\> Search-WmiHelp {$_ -like "*Disk*"}
Get-WmiObject : Invalid namespace
At C:\Documents and Settings\jcn\Desktop\Add-WmiHelpFunctions.ps1:135 char:42
+ $localizedClasses = Get-WmiObject <<<< -NameSpace $localizedNamespace -Query "select * from meta_class"
At C:\Documents and Settings\jcn\Desktop\Add-WmiHelpFunctions.ps1:140 char:109
+ Write-Progress "Searching Wmi Classes" "$count of $($localizedClasses.Count)" -Perc ($count*100/$ <<<< lo
calizedClasses.Count)
PS C:\>
In order to allow the individuals who are having localization issues to still get their wmi help, I have made culture an argument to Get-WmiHelp and Search-WmiHelp. You can specify the culture ID code in hex format. If you run:
Get-WmiObject "__Namespace" | ? { $_.Name -like "ms_*"} | Format-Table Name
You should be able to see all of the localized namespaces. http://www.microsoft.com/globaldev/reference/oslocversion.mspx#winVistaSKU can help you identify which one you would like to use. ms_409 is en-us. Pick one of these to use, and then run Get-WmiHelp or Search-WmiHelp with -cultureID 0x409 (or 0x + whatever 3 digit number was after ms_ in the namespace name for the locale you want).
Please post a comment if you had an issue, and this resolved it, or if you are still having an issue.
This is a XP Sp2 MUI + German Language Pack
30# $localizedNamespaces = Get-WmiObject -NameSpace "root\cimv2" -Class "__Namespace" | where {$_.Name -like "ms_*"}
31# $localizedNamespaces
__GENUS : 2
__CLASS : __NAMESPACE
__SUPERCLASS : __SystemClass
__DYNASTY : __SystemClass
__RELPATH : __NAMESPACE.Name="ms_409"
__PROPERTY_COUNT : 1
__DERIVATION : {__SystemClass}
__SERVER : WKS-VIE-301
__NAMESPACE : ROOT\cimv2
__PATH : \\WKS-VIE-301\ROOT\cimv2:__NAMESPACE.Name="ms_409"
Name : ms_409
__RELPATH : __NAMESPACE.Name="ms_407"
__PATH : \\WKS-VIE-301\ROOT\cimv2:__NAMESPACE.Name="ms_407"
Name : ms_407
32# $localizedNamespaces | where {$_.Name -eq "ms_{0:x}" -f (Get-Culture).LCID }
33# Get-Culture
LCID Name DisplayName
---- ---- -----------
3079 de-AT German (Austria)
34# Get-WmiObject -query "SELECT * FROM __Namespace" -namespace "root\cimv2"
__RELPATH : __NAMESPACE.Name="sms"
__PATH : \\WKS-VIE-301\ROOT\cimv2:__NAMESPACE.Name="sms"
Name : sms
__RELPATH : __NAMESPACE.Name="Applications"
__PATH : \\WKS-VIE-301\ROOT\cimv2:__NAMESPACE.Name="Applications"
Name : Applications
35# Get-LocalizedNamespace
\ms_7f
36#
Hello Powershell Team,
I don't know if this is the right place but Jeffrey did ask us to complain when we saw something stupid or when things didn't work as expected.
I am trying to use the WMISearcher object and when I pass a query that has a join, it fails. So basically, even though you can pass a standard "Select * from ..." query, you can't use a properly written WQL statement that uses joins or aliases. Or am I missing something?
Just an FYI... The latest .PS1 file is missing the '@' for the initial here string.
--Greg
.cmdletname { font-size:large } .cmdletsynopsis { font-size:medium } .cmdletdescription { font-size:medium