The [WMI] Type technique is
not for the beginner, for novices I suggest they concentrate on
Get-WmiObject. Even for experienced
PowerShell script writers I question the usefulness of the [WMI] Type
construction. While it looks flashy, the syntax is picky, therefore I am not
sure that it is better than the straightforward Get-WmiObject.
This example employs the called Win32_ComputerSystem.
By introducing variables I highlight the WMI particular class, and also remind you to change
the name of $Srv. Incidentally, neither LocalHost nor '.' works for as
a value for your computer name, see
what I mean about [WMI] Type being picky?
# [WMI] Type example Clear-Host $Srv = "Longhorn" $CimPlace
= "Root\Cimv2:Win32_ComputerSystem" [WMI]$LowDown = "$CimPlace.name='$Srv'"
$LowDown
Note 1: The reason that the above example works is that
luckily I have used the .name property, which is
the correct primary key for the WMI class Win32_ComputerSystem.
Guy
Recommends: WMI Monitor and It's Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems. Fortunately, Solarwinds
have created a
Free WMI Monitor so that you can discover these gems of performance
information, and thus improve your PowerShell scripts. Take the guess work out of which WMI counters to use when scripting the
operating system, Active Directory or Exchange Server.
Note 6: This example drove me mad. The
reason was that I introduced white space in an attempt to make the
command more readable. Introducing a space either side of the
equals sign produced the "Invalid parameter " error. Wrong,
silly me.
.DeviceID = 'C:'" Just does not work.
Neither did introducing a space between the two sets of speech marks: .DeviceID='C:' " - Wrong.
»
Summary of PowerShell [WMI] Type
PowerShell's [WMI] Type technique is not for the beginner. Even for experienced
PowerShell script writers I question the usefulness of the [WMI] Type
construction. While it looks flashy, the syntax is picky, and I am not
sure that it is better than the straightforward Get-WmiObject.
If you like this page then please share it with your friends
Please email me if you have any example scripts. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, Solarwinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.