PowerShell WMI Win32ComputerSystem

Introduction to the WMI Class Win32ComputerSystem

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.

Topics for PowerShell WMI Win32ComputerSystem

 ♣

WMI Perspective

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 Win32_ComputerSystem – Getting Started

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: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s 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. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

[WMI] Win32_ComputerSystem – More Properties

Important: It will only work if you change the value of $SysName

Clear-Host
$Comp=""
$SysName = ‘YourComputer
$CimPlace = "Root\Cimv2:Win32_ComputerSystem"
[WMI]$Comp = "$CimPlace.name=’$SysName’"
$Comp

Note 2: The above example displays not only the properties, but also any values.

Note 3: For a production script you could simplify to:
[WMI]"Root\Cimv2:Win32_ComputerSystem.name=’YourComputer’"

Naturally, change ‘YourComputer’ to the name of a real server or workstation.

WMI Class and Get-Member

Here is an alternative method which uses Get-Member to list the properties.

Clear-Host
Get-WmiObject -class Win32_ComputerSystem  `
| Get-Member -memberType property [a-z]*

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

WMI Win32ComputerSystem – Real Life Examples

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.

# Win32ComputerSystem example .DomainRole
Clear-Host
$CompConfig = Get-WmiObject Win32_ComputerSystem
foreach ($ObjItem in $CompConfig) {
$Role = $ObjItem.DomainRole
Switch ($Role) {
0 {"Standalone Workstation"}
1 {"Member Workstation"}
2 {"Standalone Server"}
3 {"Member Server"}
4 {"Backup Domain Controller"}
5 {"Primary Domain Controller"}
default {"Not a known Domain Role"}
         }
}

Note 5:  You could append -computerName otherMachine

# Win32ComputerSystem example .PCSystemType
Clear-Host
$CompConfig = Get-WmiObject -Class Win32_ComputerSystem -computer otherM
foreach ($ObjItem in $CompConfig) {
$Type = $objItem.PCSystemType
Switch ($Type) {
1 {"Desktop"}
2 {"Mobile / Laptop"}
3 {"Workstation"}
4 {"Enterprise Server"}
5 {"Small Office and Home Office (SOHO) Server"}
6 {"Appliance PC"}
7 {"Performance Server"}
8 {"Maximum"}
default {"Not a known Product Type"}
}
}

Note 6:  For PCSystemType Switch starts at 1 and not zero.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Script to Discover Your Computer’s DomainRole and PCSystemType

Clear-Host
$Victim = ‘.’
$CompConfig = Get-WmiObject -Class Win32_ComputerSystem -computer $Victim
foreach ($ObjItem in $CompConfig) {
$x = $ObjItem.PCSystemType
$Type = Switch ($x) {
1 {"Desktop"}
2 {"Mobile / Laptop"}
3 {"Workstation"}
4 {"Enterprise Server"}
5 {"Small Office and Home Office (SOHO) Server"}
6 {"Appliance PC"}
7 {"Performance Server"}
8 {"Maximum"}
default {"Not a known Product Type"}
   }
$y = $ObjItem.DomainRole
$Role = Switch ($y) {
0 {"Standalone Workstation"}
1 {"Member Workstation"}
2 {"Standalone Server"}
3 {"Member Server"}
4 {"Backup Domain Controller"}
5 {"Primary Domain Controller"}
default {"Not a known Domain Role"}
   }
}
Write-Host "Computer $Victim is a $Type and $Role "

Researching More Win32_ComputerSystem Properties

This script is getting a bit cumbersome, but my aim is just to give you ideas for a script to suit your circumstances.

Clear-Host
$Victim = ‘Jasmine’
$CompConfig = Get-WmiObject -Class Win32_ComputerSystem -computer $Victim
foreach ($ObjItem in $CompConfig) {
$Sys = $ObjItem.SystemType
$a = $ObjItem.PCSystemType
$Type = Switch ($a) {
1 {"Desktop"}
2 {"Mobile / Laptop"}
3 {"Workstation"}
4 {"Enterprise Server"}
5 {"Small Office and Home Office (SOHO) Server"}
6 {"Appliance PC"}
7 {"Performance Server"}
8 {"Maximum"}
default {"Not a known Product Type"}
   }
$b = $ObjItem.DomainRole
$Role = Switch ($b) {
0 {"Standalone Workstation"}
1 {"Member Workstation"}
2 {"Standalone Server"}
3 {"Member Server"}
4 {"Backup Domain Controller"}
5 {"Primary Domain Controller"}
default {"Not a known Domain Role"}
   }
$c = $ObjItem.AutomaticResetBootOption
$Reboot = Switch ($c) {
1 {"Reserved"}
2 {"Operating System"}
3 {"System Utilities"}
4 {"Not Set"}
default {"Puzzling"}
   }
$d = $ObjItem.AdminPasswordStatus
$Pswd = Switch ($d) {
0 {"Disabled"}
1 {"Enabled"}
2 {"Not Implemented"}
3 {"Unknown"}
default {"Puzzling"}
   }
$e = $ObjItem.WakeUpType
$WakeUp = Switch ($e) {
0 {"Unknown"}
1 {"Unsupported"}
2 {"Disabled"}
3 {"Enabled – Standard Settings"}
4 {"Power Saving Auto"}
5 {"Power State Settable"}
6 {"Power Cycling Supported"}
7 {"Timed Power-On Supported"}
default {"Strange Power Setting"}
   }
$f = $ObjItem.WakeUpType
$WakeUp = Switch ($f) {
0 {"Reserved"}
1 {"Other"}
2 {"Unknown"}
3 {"APM Timer"}
4 {"Modem Ring"}
5 {"Lan Remote"}
6 {"Power Switch"}
7 {"PCI PME#"}
8 {"AC Power Restored"}
default {"Unusual Wakeup Setting"}
    }
          }
Write-Host "Computer $Victim, $Sys is a $Type and $Role with $Reboot, $Wakeup "

Guy Recommends: SolarWinds Free Network Bandwidth MonitorFree Real-Time Bandwidth Monitor

This freeware monitor is great for checking whether your network’s load-balancing is performing as expected, for example, are two interfaces are getting about equal traffic?

It’s easy to install and straightforward to configure. You will soon be running tests to see how much network bandwidth your applications consume.

The GUI has a lovely balance between immediate network traffic data in the middle, combined with buttons to seek related data and configuration settings. Give this monitor a try, it’s free! 

Download your free network bandwidth monitor

If you need more comprehensive network analysis software:
Download a free trial of NPM (Network Performance Monitor)

Researching More WMI Classes

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

Get-WmiObject -List | Where-Object {$_.name -Match "Win32"}

And even better:

Get-WmiObject -List |Where-Object {$_.name -Match "Win32"} `
 | Out-File D:\wmi\win.txt

Learning Points

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

 


See More Microsoft PowerShell WMI Examples:

Home   • PowerShell Get-WmiObject   • Win32_ComputerSystem   • Free WMI Monitor

WMI Class  • [WMI] Type  • Win32_printer   • Win32_product   • SystemRestore   • WMI Services

WMI Disk   • DNS   • Memory  • PowerShell -Filter   • Check Server UpTime   • ConvertToDateTime

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.