Forum Discussion
Audi86
Aug 24, 2022Brass Contributor
Add a line to skip or continue loop execution
Hi I have a PS script which is terminating workflows in SharePoint. I don't want to run this script in one go rather I want to add user intervention as well. Below is my script portion. In line 44, I...
- Aug 25, 2022If you want to skip to the next loop iteration, without existing the loop/script, use the continue statement: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_continue?view=powershell-7.2
VasilMichev
Aug 25, 2022MVP
If you want to skip to the next loop iteration, without existing the loop/script, use the continue statement: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_continue?view=powershell-7.2
Audi86
Aug 25, 2022Brass Contributor
VasilMichev using LainRobertson code, what will be my code with continue command. Is it something like that?
{
if (Read-Host -Prompt "Do you want to Terminate this instance:" -in @("n", "no"))
{
Continue
}
$Ctx.ExecuteQuery() ;
Write-host -f Green "'$($WorkflowAssociations | Where-Object {$_.ID -eq $WorkflowInstance.WorkflowSubscriptionId} | Select-Object -ExpandProperty Name)'is Terminated";
return;
}
{
if (Read-Host -Prompt "Do you want to Terminate this instance:" -in @("n", "no"))
{
Continue
}
$Ctx.ExecuteQuery() ;
Write-host -f Green "'$($WorkflowAssociations | Where-Object {$_.ID -eq $WorkflowInstance.WorkflowSubscriptionId} | Select-Object -ExpandProperty Name)'is Terminated";
return;
}