首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单台服务器上的get-hotfix

单台服务器上的get-hotfix
EN

Stack Overflow用户
提问于 2011-08-09 19:48:39
回答 1查看 1.4K关注 0票数 2

第一次使用powershell时,我似乎无法让下面的代码正常工作--没有显示任何内容--我认为脚本可以工作,但我想我需要一些东西来显示结果?如果有任何帮助,请:

代码语言:javascript
复制
$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 -我已经将其更新为:

代码语言:javascript
复制
 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 ""
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-09 20:04:49

代码不会输出任何内容,因为您将其赋给了一个变量。删除分配。您还将命令输出分配给$hotfix1,但在if语句中对照$hotfix进行检查。此外,如果找不到热修复程序,您将得到一个错误,因此添加-ErrorAction参数以抑制错误:

代码语言:javascript
复制
$hotfix1 = Get-HotFix -Id KB981872 -ErrorAction SilentlyContinue

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

$hotfix1
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6995697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档