Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



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: WMI Monitor and It's Free!Solarwinds Free WMI Monitor

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.

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.

Solarwinds Network Device MonitorGuy Recommends Solarwinds' Free Network Monitor

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. 

Download your free Network Device 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: A Free Wake-On-LAN UtilitySolarwinds Wake-On-LAN

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. 

Download your free copy of Wake-On-LAN

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   • WMI Services   • Win32_ComputerSystem

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

WMI Disk   • DNS   • PowerShell -Filter   • Windows PowerShell   • Memory

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.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

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.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.