powershell - Try/Catch...but want to continue on error, not -ErrorAction Stop -


i'm still bit of novice when comes scripting have come long way. need try/catch on following, confused on it. research show, shows -erroraction stop....but in case, if there error...continue....i think. here's dealio. section of script checks see if site exists, if doesn't .... great...continue script. if exist, stop , write out stuff , end script there. try/catch confusing me. can help?

$urlis = "https://ourdevsite.dev.com/sites/$myvar"  add-pssnapin microsoft.sharepoint.powershell -ea 0  if (-not(get-spweb $urlis)){     write-host "site not exist, can proceed building it" -foregroundcolor green     } else { write-host "site exist, need pick url" -foregroundcolor red } 

you don't need change erroraction, use exit keyword stop script:

add-pssnapin microsoft.sharepoint.powershell  $url = "https://ourdevsite.dev.com/sites/$myvar"  if (get-spweb $url) {     write-host "site exist, need pick url" -foregroundcolor red     exit } else {     write-host "site not exist, can proceed building it" -foregroundcolor green } 

i don't have sharepoint environment, i'm assuming get-spweb check works , returns true/false.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -