Powershell检查远程工作站上的Windows操作系统版本

时间:2014-08-07 03:01:40

标签: powershell

我希望在远程工作站上找到它的Windows版本。 我需要从$ OSCheck中提取信息,然后检查它是否与Windows版本匹配。

$computer = read-host "Computer Name "
$UserName = Read-Host "Enter User Name "
$Password = Read-Host -AsSecureString "Enter Your Password "
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName , $Password
#Check Workstation#
$OSCheck = (Get-WmiObject -comp $computer -Credential $Credential -class Win32_OperatingSystem ).Caption    
$OSCheck
Write-Host ""
#Write-Host "OS Version is - " $OSCheck
Write-Host ""

If ($OSCheck  -match "Microsoft Windows 7 Professional" )
{
    Write-Host "OSCheck is Microsoft Windows 7 Professional"
}
Else
{
    Write-Host "Not Windows 7"
}

2 个答案:

答案 0 :(得分:1)

在您的脚本中,您使用$ comp作为计算机读取主机,但对于您的wmi查询,您使用的是$ computer

答案 1 :(得分:0)

更新了脚本,现在正在使用 更改了以下内容 -

$OSCheck = (Get-WmiObject -comp $computer -Credential $Credential -class Win32_OperatingSystem ).Caption

所以它将我要检查的变量传递给变量。上一行太复杂了。这是一种更简单的方法。

相关问题