Get-OsVersion.ps1
#requires -Version 2.0 Function Get-OsVersion { <# .SYNOPSIS Gets Version Information about a Computer using WMI. .DESCRIPTION To get correct Version-Information about a Computer, you have to use WMI. Unfortunately, the returned Object is not simple to use, as the Version and Revision are returned as string and the Build doesn´t clearly state which Release of Windows you use. Get-OSVersion returns a Version-Object with numeric Version-Number so that you can use a comparison-Operator to check for minimal OS-Version. You can also check for Client or Server and the Output will resolve which Windows 10 Release you are using in a clearly readable Format. Get-OSVersion also supports remote Execution and the Pipeline. .EXAMPLE Get-OsVersion Caption : Microsoft Windows Server 2016 Datacenter OSArchitecture : 64-Bit VersionNumber : 10 Computername : DC1 Revision : Windows 10 1607 OSType : Server BuildNumber : 14393 Returns a simple Object with OS-Versioninformation .EXAMPLE Get-OsVersion -Computername Server1 -Credential netz-weise\admin Caption : Microsoft Windows Server 2016 Datacenter OSArchitecture : 64-Bit VersionNumber : 10 Computername : DC1 Revision : Windows 10 1607 OSType : Server BuildNumber : 14393 Returns the Version-Information of Server1. Credential is optional, if your current credentials have no permissions on the remote System. .NOTES Place additional notes here. #> [cmdletBinding()] param( [parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true )] [string[]]$ComputerName = '.', [PSCredential]$Credential ) Begin { $OsVersionList = @{ 17763 = 'Windows 10 1809' 17134 = 'Windows 10 1803' 16299 = 'Windows 10 1709' 15063 = 'Windows 10 1703' 14393 = 'Windows 10 1607' 10586 = 'Windows 10 1511' 10240 = 'Windows 10 1507' 9600 = 'Windows 8.1 Update 1' 9200 = 'Windows 8.1 or 8, depending on Version Number' 7601 = 'Windows 7, SP1' 7600 = 'Windows 7' 6002 = 'Vista SP2' 6001 = 'Vista SP1' 6000 = 'Vista' 2600 = 'Windows XP' } } Process { $OsData = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName -Credential $Credential If ( $OsData.Caption -like '*Server*' ) { $OsType = 'Server' } else { $OsType = 'Client' } $VersionData = @{ Computername = $OsData.PSComputerName VersionNumber = [double](($OsData.version.split('.') | Select-Object -first 2) -join '.') Revision = $OsVersionList.([int]$OsData.BuildNumber) BuildNumber = $OsData.BuildNumber Caption = $OsData.Caption OSArchitecture = $OsData.OSArchitecture OSType = $OsType } New-Object -TypeName PSObject -Property $VersionData } } |