I recently needed to find the operating system using PowerShell – preferably the full name (“Microsoft Windows 10 Enterprise”) as opposed to the version (10.0.17763).
When researching this I stumble upon lots of ways to achieve this, some more reliable than others. And some which require the most recent versions of PowerShell.
I prefer to use methods that are as compatible as possible with older versions of PowerShell. And the best two ways to achieve this are as follows:
Use WMI to Find the Operating System using PowerShell
#show all properties for reference only
(Get-WMIObject win32_operatingsystem) | select *
#retrieve OS
$OS1 = (Get-WMIObject win32_operatingsystem).caption
#write it out
write-host $OS1
Use Systeminfo to Find the Operating System using PowerShell
#show all properties for reference only
systeminfo /fo csv | ConvertFrom-Csv | select *
#retrieve OS
$OS2 = systeminfo /fo csv | ConvertFrom-Csv | select "OS Name" | select -ExpandProperty "OS Name"
#write it out
write-host $OS2