gpt4 book ai didi

powershell - 单服务器上的get-hotfix

转载 作者:行者123 更新时间:2023-12-02 23:05:44 24 4
gpt4 key购买 nike

第一次使用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 ""
}

最佳答案

该代码不会输出任何内容,因为您将其分配给了变量。删除任务。您还将命令输出分配给$ 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

关于powershell - 单服务器上的get-hotfix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6995697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com