PowerShell WMI – Querying Operating System informations

Hi Guys,

Here is a small function I wrote to gather the Operating System basic informations.
[ps]Function Get-OSInfo {
Query WMI of the computer to provide basic OS Information.

.PARAMETER ComputerName
The computer name or IP of targeted computer.

Author: Thomas Prud’homme (Twitter: @prudhommewtf).

[String]$ComputerName = $env:COMPUTERNAME
Begin {
# Win32_OperatingSystem: http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx
$Win32_OperatingSystem = Get-WmiObject -Namespace root\CIMV2 -Class Win32_OperatingSystem -Property Name, CSDVersion, InstallDate, OSLanguage, Version, WindowsDirectory -ComputerName $ComputerName
Process {
Write-Verbose -Message ‘Operating System gathered information:’
$Output = @()
$Win32_OperatingSystem | ForEach-Object {
$OSInfo = New-Object -TypeName PSObject -Property @{
Name = $_.Name.split(‘|’)[0].Trim()
ServicePack = $_.CSDVersion
InstallDateUTC = $Win32_OperatingSystem.ConvertToDateTime($_.InstallDate).ToUniversalTime()
Language = Invoke-OSLanguage -LanguageCode $_.OSLanguage
Version = New-Object -TypeName System.Version -ArgumentList $_.Version
WindowsDirectory = $_.WindowsDirectory
VersionNumber = (New-Object -TypeName System.Version -ArgumentList $_.Version).Major

$OSInfo.psobject.Properties | ForEach-Object {
Write-Verbose -Message "`t$($_.Name): $($_.Value)"

$Output += $OSInfo
End {
Write-Output -InputObject $Output

For the purpose of this function I wrote a matching function to translate the OSLanguage digits to a more convinent string. You can find the matching function here

See you,