Here's a great way to get the operating system name, service pack and architecture of a local computer.

This tiny script uses WMI to first gather the necessary attributes about the operating system.

## Gather the Caption (OS Name), CSDVersion (Service Pack) and OSArchitecture (x86 or x64)
$OsAttribs = Get-WmiObject -Class Win32_OperatingSystem | select caption,csdversion,osarchitecture

## If CSDVersion (Service Pack) is null then I'm assuming this means no service pack at all so it's actually RTM (Release to Manufacturing)
$ServicePack = @{$true = $OsAttribs.CSDVersion; $false = 'RTM'}[$OsAttribs.CsdVersion -ne $null]

## Use the [pscustomobject] type accelerator to create a custom object from a hash table with all the attributes
## Always output objects if you can from your scripts

Join the Jar Tippers on Patreon

It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!

Become a Patron!