【发布时间】:2020-03-06 19:47:07
【问题描述】:
有一个命令(在 2008 机器上)由于缓冲区限制而引发异常。
基本上,脚本会停止 WAUA,破坏 SoftwareDistribution,然后重建 SD 并检查针对 WSUS 的更新,然后重新签入以使 WSUS 中的警报停止。
如果抛出异常,我希望特定行重试,直到它完成而没有异常,然后我们可以告诉它向 WSUS 报告以清除它。
Stop-Service WUAUSERV
Remove-Item -Path C:\WINDOWS\SoftwareDistribution -recurse
Start-Service WUAUSERV
GPUpdate /force
WUAUCLT /detectnow
sleep 5
## This is the command I'd like to loop, if possible, when an exception is thrown ##
$updateSession = new-object -com "Microsoft.Update.Session"; $updates=$updateSession.CreateupdateSearcher().Search($criteria).Updates
WUAUCLT /reportnow
任何形式的帮助将不胜感激。我所能找到的一切都是如何创建自己的异常,而不是如何在抛出异常时处理它并重试直到它完成而没有错误。
编辑:
然后根据下面的答案,我希望它是这样写的,所以它会继续检查,直到它成功运行,然后它会重新报告?
Stop-Service WUAUSERV
Remove-Item -Path C:\WINDOWS\SoftwareDistribution -recurse
Start-Service WUAUSERV
GPUpdate /force
WUAUCLT /detectnow
sleep 5
while(-not $?) {$updateSession = new-object -com "Microsoft.Update.Session"; $updates=$updateSession.CreateupdateSearcher().Search($criteria).Updates}
WUAUCLT /reportnow
【问题讨论】:
标签: windows powershell exception