2011-08-09 27 views
2

首次使用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 

由于吉文 - 我已经更新了它:

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 "" 
} 
+0

太好了。有一件事,我会改变这一行:'If($ hotfix1 -match“KB979808”)'to'If($ hotfix1.HotFixID -eq'KB979808')',或简单地'If($ hotfix1)...' –

回答

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 
+0

梦幻般的谢伊 - 非常感谢。 – lara400

相关问题