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
}On my own laptop:

On my machine it returns this:

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.MinutesDisk 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 -AutoSizeDeviceID 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
Need something that is not in the block? Ask Claude which CIM class holds it, the graphics card or the installed updates for example, and for the line to add.
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, LastBootUpTimeGet-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.
Leave a Reply