第一次使用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
Run Code Online (Sandbox Code Playgroud)
谢谢谢伊 - 我已将其更新为:
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 ""
}
Run Code Online (Sandbox Code Playgroud)
代码不会输出任何内容,因为您将其分配给变量.删除作业.您还将命令输出分配给$ 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1304 次 |
| 最近记录: |