【发布时间】:2015-04-25 05:42:02
【问题描述】:
我有一个将计算机添加到域的 powershell 脚本。有时,当我运行脚本时,会出现以下错误,而当我第二次运行它时,它会起作用。 如何制作脚本来检查我是否收到此错误,如果是,然后重试将其添加到域中? 我已经读到很难尝试捕获这样的错误。那是对的吗?是否有更好/不同的方法来捕获错误?
谢谢!
代码:
if ($localIpAddress -eq $newIP)
{ # Add the computer to the domain
write-host "Adding computer to my-domain.local.. "
Add-Computer -DomainName my-domain.local | out-null
} else {...}
错误:
由于以下错误,此命令无法在目标计算机('computer-name')上执行:指定的域不存在或无法联系。
【问题讨论】:
标签: powershell error-handling try-catch catch-block