第一次使用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 ""
}发布于 2011-08-09 20:04:49
代码不会输出任何内容,因为您将其赋给了一个变量。删除分配。您还将命令输出分配给$hotfix1,但在if语句中对照$hotfix进行检查。此外,如果找不到热修复程序,您将得到一个错误,因此添加-ErrorAction参数以抑制错误:
$hotfix1 = Get-HotFix -Id KB981872 -ErrorAction SilentlyContinue
If($hotfix1)
{
"Hotfix is installed you may proceed"
}
else
{
"Hotfix is not installed"
}
$hotfix1https://stackoverflow.com/questions/6995697
复制相似问题