Try/Catch...但想在出现错误时继续,而不是 -ErrorAction Stop
Try/Catch...but want to continue on error, not -ErrorAction Stop
在脚本编写方面,我仍然是个新手,但已经走了很长一段路。我需要在下面做一个 Try/Catch,但对此感到困惑。我展示的所有研究都显示 -ErrorAction Stop....但在这种情况下,如果有错误......继续......我认为。这是交易。
脚本的这一部分检查站点是否存在,如果不存在……太棒了……继续脚本。如果确实存在,请停止并写出一些内容并在那里结束脚本。
所以 TRY/CATCH 让我感到困惑。你能帮忙吗?
$URLis = "https://ourdevsite.dev.com/sites/$myVar"
add-pssnapin microsoft.sharepoint.powershell -ea 0
If (-not(Get-SPWeb $URLis)){
Write-Host "Site does not exist, so we can proceed with building it" -foregroundcolor green
}
Else {
Write-Host "Site does exist, so we need to pick another URL" -foregroundcolor red
}
您无需更改 ErrorAction,只需使用 exit
关键字即可停止脚本:
add-pssnapin microsoft.sharepoint.powershell
$URL = "https://ourdevsite.dev.com/sites/$myVar"
If (Get-SPWeb $URL) {
Write-Host "Site does exist, so we need to pick another URL" -foregroundcolor red
exit
}
Else {
Write-Host "Site does not exist, so we can proceed with building it" -foregroundcolor green
}
我没有 Sharepoint 环境,所以我假设您的 Get-SPWeb
检查已经有效并且 returns true/false.
在脚本编写方面,我仍然是个新手,但已经走了很长一段路。我需要在下面做一个 Try/Catch,但对此感到困惑。我展示的所有研究都显示 -ErrorAction Stop....但在这种情况下,如果有错误......继续......我认为。这是交易。 脚本的这一部分检查站点是否存在,如果不存在……太棒了……继续脚本。如果确实存在,请停止并写出一些内容并在那里结束脚本。 所以 TRY/CATCH 让我感到困惑。你能帮忙吗?
$URLis = "https://ourdevsite.dev.com/sites/$myVar"
add-pssnapin microsoft.sharepoint.powershell -ea 0
If (-not(Get-SPWeb $URLis)){
Write-Host "Site does not exist, so we can proceed with building it" -foregroundcolor green
}
Else {
Write-Host "Site does exist, so we need to pick another URL" -foregroundcolor red
}
您无需更改 ErrorAction,只需使用 exit
关键字即可停止脚本:
add-pssnapin microsoft.sharepoint.powershell
$URL = "https://ourdevsite.dev.com/sites/$myVar"
If (Get-SPWeb $URL) {
Write-Host "Site does exist, so we need to pick another URL" -foregroundcolor red
exit
}
Else {
Write-Host "Site does not exist, so we can proceed with building it" -foregroundcolor green
}
我没有 Sharepoint 环境,所以我假设您的 Get-SPWeb
检查已经有效并且 returns true/false.