How to Get System Information with PowerShell

📜Part of the PowerShell Complete Guide, every PowerShell post on this site, grouped by the job you are doing.
The short answer

Use Get-CimInstance, not the old Get-WmiObject. Win32_OperatingSystem and Win32_ComputerSystem answer most of it.

When you pick up an unfamiliar server, the same handful of questions come first. This is the block I keep for answering all of them at once.

The Summary Block

$os = Get-CimInstance Win32_OperatingSystem
$cs = Get-CimInstance Win32_ComputerSystem

[pscustomobject]@{
    ComputerName = $env:COMPUTERNAME
    OS           = $os.Caption
    Version      = $os.Version
    Manufacturer = $cs.Manufacturer
    RAM_GB       = [math]::Round($cs.TotalPhysicalMemory / 1GB, 1)
    CPUs         = $cs.NumberOfLogicalProcessors
    LastBoot     = $os.LastBootUpTime
}

Which returns something like this:

ComputerName : APPSRV01
OS           : Microsoft Windows Server 2022 Standard
Version      : 10.0.20348
Manufacturer : HP
RAM_GB       : 64
CPUs         : 16
LastBoot     : 18/08/2026 23:17:03

Uptime

Uptime is not a property, it is a subtraction, which is why people struggle to find it:

$os = Get-CimInstance Win32_OperatingSystem
$up = (Get-Date) - $os.LastBootUpTime
"Up for {0}d {1}h {2}m" -f $up.Days, $up.Hours, $up.Minutes

Disk Space

Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
    Select-Object DeviceID,
        @{N='SizeGB'; E={[math]::Round($_.Size / 1GB, 1)}},
        @{N='FreeGB'; E={[math]::Round($_.FreeSpace / 1GB, 1)}},
        @{N='Free%';  E={[math]::Round($_.FreeSpace / $_.Size * 100, 1)}} |
    Format-Table -AutoSize
DeviceID SizeGB FreeGB Free%
-------- ------ ------ -----
C:        106.2   28.4  26.7
D:        369.1  281.8  76.3

DriveType=3 means fixed local disks, which keeps network drives and USB sticks out of the answer.

Serial Number and Model

Get-CimInstance Win32_BIOS | Select-Object SerialNumber, Manufacturer
Get-CimInstance Win32_ComputerSystem | Select-Object Model, Domain

Running It Against Another Machine

Every Get-CimInstance call takes -ComputerName, so the same block works remotely with WinRM enabled:

Get-CimInstance Win32_OperatingSystem -ComputerName APPSRV01, APPSRV02 |
    Select-Object PSComputerName, Caption, LastBootUpTime
Use CIM, not WMI. Get-WmiObject still works in Windows PowerShell 5.1 but is deprecated and absent from PowerShell 7. Get-CimInstance is the replacement, uses WinRM rather than DCOM for remoting, and is friendlier through firewalls.

Related


If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Looking for SQL Server?

This site started as a SQL Server blog in 2017 and the archive is still here. The new SQL Server writing, and all the scripts, moved to a site of their own.

sqldba.blogScripts, error library, wait types, SSMS
Browse by topic