PowerShell for Windows Admins

Jan 22 2014   12:30PM GMT

Win32_OperatingSystem examples

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The Win32_ComputerOperatingSystem class can provide a good deal of information about the OS installed on your machines. These examples are converted from those presented here: http://msdn.microsoft.com/en-us/library/aa394596%28v=vs.85%29.aspx

# ServicePack version

Get-CimInstance -ClassName Win32_OperatingSystem |

select ServicePackMajorVersion, ServicePackMinorVersion

# install date of OS

Get-CimInstance -ClassName Win32_OperatingSystem |

select Installdate

# Windows version

Get-CimInstance -ClassName Win32_OperatingSystem |

select Caption, Version

# windows folder

Get-CimInstance -ClassName Win32_OperatingSystem |

select WindowsDirectory

# all

Get-CimInstance -ClassName Win32_OperatingSystem |

select Caption, Version, ServicePackMajorVersion,

ServicePackMinorVersion, Installdate, WindowsDirectory

You could create a function:

function get-OS {

[CmdletBinding()]

param(

[string]$computername = $env:COMPUTERNAME

)

Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $computername|

select Caption, Version, ServicePackMajorVersion,

ServicePackMinorVersion, Installdate, WindowsDirectory

}

and then choose properties if required:

£> get-OS | Format-Table Caption, Installdate

Caption                                       Installdate

——-                                           ———–

Microsoft Windows 8.1 Pro    05/12/2013 10:16:49

£> get-OS

Caption : Microsoft Windows 8.1 Pro

Version : 6.3.9600

ServicePackMajorVersion : 0

ServicePackMinorVersion : 0

Installdate : 05/12/2013 10:16:49

WindowsDirectory : C:\windows

£> get-OS | Format-Table Caption, Service* -AutoSize

Caption                                    ServicePackMajorVersion   ServicePackMinorVersion

——-                                         ———————–             ———————–

Microsoft Windows 8.1 Pro   0                                              0

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: