Terminate remote script as Failure

Asked

Viewed 34 times

0

I want the remote script in a given condition to end with error and exit as Failure.

if (($siteExists -eq $null) -and ($siteExistsInRecycleBin -eq $null)) {
write-output "info: Creating $($SiteCompleto)" 
New-SPOSite -Url $SiteCompleto -title $TituloFinal -Owner $Proprietario -StorageQuota '5' -NoWait -ResourceQuota '100' -Template 'STS#0'
}
elseif ($siteExists -eq $true){
write-output "info: $($SiteCompleto) already exists"
stop
}
else{
write-output "info: $($SiteCompleto) still exists in the recyclebin"
stop

I need that in case the Sharepoint site already exists that the script is stopped and exit as if there was an error of execution, something similar to Kill -9 of the linux scripts. I am running this script remotely through an orchestrator who only handles Success or Failure.

As the stop command does not exist, the effect when I use it the result is what I want, abort the script with error, but actually the code is wrong and is not elegant at all the solution

  • Welcome to the site. You can edit the question and explain in more detail what you intend to do with this code?

  • I need that in case the Sharepoint site already exists that the script is stopped and exit as if there was an error of execution, something similar to Kill -9 of the linux scripts. I am running this script remotely through an orchestrator who only handles Success or Failure

  • Claudio, click EDIT and add this explanation to the question :)

1 answer

0

I was able to resolve using the "error message" throw command, this command also sends the returnCode=1 and stops the execution of the script and my Orchestration stream receives the returncode and treats as Failure :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.