, .
, 2003, , If .
Wrong
TessellatingHeckler, , , , , PowerShell .
, , . , ForEach. If {} Switch, , , , , . .
, , , , , .
$Computer = (gc c:\servers.txt)
ForEach ($system in $computer){
$BuildVersion = Get-WmiObject -Class Win32_OperatingSystem -Property Version, CSName -ComputerName $system -ErrorAction SilentlyContinue
$Build=$BuildVersion.version
switch ($build){
"5.2.3790" {$Build="2003"}
"6.1.7601" {$Build="2008"}
"6.3.9600" {$Build="2012"}
}
[pscustomobject]@{Server=$system;OSVersion=$build;CSName=$buildVersion.CSname}
}
>Server OSVersion CSName
------ --------- ------
dc2012 2012 DC2012
sccm1511 2012 SCCM1511