function Test-PSVersion { [CmdletBinding()] param( [parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNullOrEmpty()] [String[]] $ComputerName = @('.'), [Parameter()] [ValidateNotNull()] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) process { if (Test-Connection -ComputerName $computername -Count 1 -ErrorAction SilentlyContinue) { try { $OS = Get-WmiObject -Namespace root\CIMV2 -Class Win32_OperatingSystem ` -ComputerName $computername -Credential $credential -ErrorAction SilentlyContinue if ($OS) { $path = "$($OS.SystemDirectory -replace '\\','\\')\\WindowsPowerShell\\v1.0\\powershell.exe" $OSName = $OS.Name.Split('|')[0] $query = "SELECT Version FROM CIM_DataFile WHERE Name = '$path'" $PSEXE = Get-WmiObject -Query $query -ComputerName $computername -Credential $credential if ($PSEXE.Version) { $buildversion = $PSEXE.Version.Split()[0] $versionPresent = [version]$buildversion $versionRequired = [version]'6.0.6002.18111' if ($versionPresent -ge $versionRequired) { $psversion = "V2 RTM" } elseif ($versionPresent.Major -ge 6) { $psversion = "V2 CTP Prerelease - Update to V2 RTM!" } else { $psversion = "V1" } New-Object PSObject -Property @{ ComputerName=$OS.__SERVER; BuildVersion=[version]$buildversion Version=$psversion; Status=$true;Description='OK'; OSName = $OSName } } else { New-Object PSObject -Property @{ ComputerName=$computername[0]; BuildVersion=[version]$null; Version='n/a'; Status=$false; Description='Unable to access OS information via WMI.'; OSName = 'n/a' } } } } catch { New-Object PSObject -Property @{ ComputerName=$computername[0]; BuildVersion=[version]$null; Version='n/a'; Status=$false; Description=($_.Exception.Message); OSName='n/a' } continue } } else { New-Object PSObject -Property @{ ComputerName=$computername[0]; BuildVersion=[version]$null; Version='n/a'; Status=$false; Description='Computer did not respond to ping, skipped.'; OSName='n/a' } } } } "localhost", "pc77", "localhost", "storage1" | Test-PSVersion