单个服务器上的get-hotfix

时间:2011-08-09 11:48:39

标签: powershell

第一次使用powershell而我似乎无法让下面的内容工作 - 没有显示任何内容 - 我认为脚本有效但我认为我需要一些东西来显示结果?请帮忙:

$hotfix1 = Get-HotFix -Id KB981872

If($hotfix)
{
$Output = "Hotfix is installed you may proceed"
}
else
{
$Output = "Hotfix is not installed"
}
$hotfix1 = Get-HotFix -Id KB981872

谢谢Shay - 我已将其更新为:

 write-host "This will check if Hotfix KB979808 is installed on this Server." -ForegroundColor 

Black -BackgroundColor Cyan
write-host "This is required for Windows Server 2008 R2 DFSR Pre-Seeding Robocopying"  -

ForegroundColor Black -BackgroundColor Cyan
Write-Host ""

$hotfix1 = Get-HotFix -Id KB979808 -ErrorAction SilentlyContinue

If($hotfix1 -match "KB979808")
{
    Write-Host "Hotfix is installed you may proceed" -foregroundcolor "green"
    Write-Host ""
}
else
{
    Write-Host "Hotfix is NOT installed - Please ensure you install this hotfix BEFORE"
    Write-host "copying any data" -foregroundcolor "red"
    Write-Host ""
}

1 个答案:

答案 0 :(得分:5)

代码不输出任何内容,因为您将其分配给变量。删除作业。您还将命令输出分配给$ hotfix1,但在if语句中检查$ hotfix。此外,如果找不到热修复,您将收到错误,因此添加-ErrorAction参数以抑制错误:

$hotfix1 = Get-HotFix -Id KB981872 -ErrorAction SilentlyContinue

If($hotfix1)
{
   "Hotfix is installed you may proceed"
}
else
{
    "Hotfix is not installed"
}

$hotfix1