更新时间:2023-02-06 11:13:00
您正在运行外部命令.这些通常不会抛出 PowerShell 异常.改为评估 $LASTEXITCODE
:
You're running external commands. Those usually don't throw PowerShell exceptions. Evaluate $LASTEXITCODE
instead:
$output = & schtasks.exe /S $server1 /delete /tn Task_InstallUpdates /f 2>&1
if ($LASTEXITCODE -ne 0) {
LogWrite "$server1 : Error deleting scheduled task - $output"
}
# create scheduled task
$output = & schtasks.exe $arguments 2>&1
if ($LASTEXITCODE -ne 0) {
LogWrite "$server1 : Error creating scheduled task - $output"
}