Remote inventory of OperatingSystem and Service Pack


param( [string] $ServerName) 


## check the machine is pingable
$query = "select * from win32_pingstatus where address = '$ServerName'"
$result = Get-WmiObject -query $query

if ($result.protocoladdress) {
   $Win32_OS = Get-WmiObject Win32_OperatingSystem -computer $ServerName | select Name, OSArchitecture, servicepackmajorversion, BuildNumber, CSName, CSDVersion, OperatingSystemSKU

   # OS Name
   $os = $Win32_OS.Name

   # 32 or 64 bit
   $bitness = $Win32_OS.OSArchitecture

   # Service pack level
   $servicepack = $Win32_OS.servicepackmajorversion

   # Build Number
   $build = $Win32_OS.BuildNumber

   # Name of the machine
   $machineName = $Win32_OS.CSName

   # Windows Edition (home, enterprise etc)
   $edition = $Win32_OS.OperatingSystemSKU

   "Operating System: $os Service Pack: $servicepack"
   "Operating System: $os Service Pack: $servicepack" | out-file -filepath C:\ServicePack.txt
} else {
            "$ServerName Not Responding" }

Run the script above with:
PS C:\ ./GetOSVersion.ps1 MyServerName

“The hero has died as a modern man; but as eternal man - perfected, unspecific, universal man, - he has been reborn” ~ Joseph Campbell


Get-WMIobject - Get WMI class information
VER - Display version information
WQL (WMI Query Language) -

Copyright © 1999-2017
Some rights reserved