The WMI class
Win32ComputerSystem contains useful properties such as PCSystemType and
DomainRole. We can use PowerShell to display information about these
and other computer properties.
Whenever I work with WMI it reminds me that the operating system must know everything that's going on! Therefore,
provided the PowerShell script has sufficient rights, it can use WMI and tap
into that vast fountain of operating system knowledge. I think of WMI
as a database, which keeps information about a computer's components such as
PCSystemType and DomainRole.
Get-WmiObject is the key command. As we will see, the class
Win32_Computer holds a rich source of data about the computer, much of which
is not displayed in the System Icon in the control panel, or any other GUI.
# List Win32_ComputerSystem properties Clear-Host Get-WmiObject
-class Win32_ComputerSystem
Note 1: Provided Win32_ComputerSystem follows directly
after Get-WmiObject you can omit -class because PowerShell assumes the first
word is a WMI class.
Problem: The above script does not display many
properties. Solution: Employ [WMI] or Get-Member see
below...
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 4: You could simplify by stripping out the
parameter and using aliases, however, you still need the name of the WMI
class: Gwmi Win32_ComputerSystem | gm
The idea of the following script is to interrogate the operating system
for information about the Domain Role (Standalone or Member) and PC System
Type (Laptop or Desktop). Once again, Win32ComputerSystem is the crucial WMI
class.
Thus utility makes it easy to check the health of a router or
firewall. Check the real-time performance, and availability statistics, for any device
on your network. Get started with an extensive collection of "out-of-the-box"
monitors for popular network devices.
Encouraging computers to sleep when not in use is a great idea -
until you are away from your desk and need a file on that remote sleeping machine!
Wake-On-LAN really will save you that long walk to awaken a hibernating
machine; however my reason for encouraging you to download this utility is
just because it's so much fun sending those 'Magic Packets'. As Wake-On-LAN (WOL) is free, see
if I am right, and you get a kick from arousing those sleeping machines.
WOL also has business uses for example, wakening machines so that they can have
their patches applied.
I was curious to discover what other WMI Objects were available for scripting; then I remembered the -list switch from another PowerShell command (Get-Eventlog -list). Thus I tried:
# PowerShell Get-WmiObject example to list classes Clear-Host
Get-WmiObject -list
Next, I redirected the output from the screen to a file by appending 'Out-File': out-File WmiObject.txt. To make:
# PowerShell Get-WmiObject example Clear-Host Get-WmiObject -list |
Out-File WmiObject.txt
Researching WMI Classes with
'Where-Object'
My next problem was the list was
too long, therefore I added a 'Where' filter
Note 1: The tiny backtick (`) tells PowerShell that the command
continues on the next line.
Note 2: On other pages I use plain 'Where', or even '?' instead of the full 'Where-Object'.
Note 3: I expect you have guessed that PowerShell commands are case insensitive. At present I am not sure which
is best, WmiObject, wmiObject or WmiObject - they all produce the same results. Another minor point,
since the verb 'get' is the default, you can shorten the command to: WmiObject
Win32_computersystem. Or if you like aliases: gwmi Win32_computersystem.
»
Summary of PowerShell WMI Win32_ComputerSystem
The PowerShell WMI class Win32ComputerSystem reveals properties such as
PCSystemType and DomainRole. You can use PowerShell to display
information about these and many other computer properties.
If you like this page then please share it with your friends
Please email me if you have a script examples. 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.