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
LainRobertson
Aug 25, 2022Silver Contributor
Focusing on this part of your problem statement:
"... when I press yes then it executes the next command and terminate the script ..."
I'd suggest this as a replacement for your original lines 44 to 46:
if (Read-Host -Prompt "Do you want to Terminate this instance:" -in @("y", "yes"))
{
$Ctx.ExecuteQuery() ;
Write-host -f Green "'$($WorkflowAssociations | Where-Object {$_.ID -eq $WorkflowInstance.WorkflowSubscriptionId} | Select-Object -ExpandProperty Name)'is Terminated";
return;
}
I don't work with SharePoint, but I do wonder if the original line 43 could also be moved inside this block?
Still, this has the desired effect of only executing the termination if either "y" or "yes" is entered, and if something else is entered, proceeding to the next iteration.
Cheers,
Lain
- Audi86Aug 25, 2022Brass Contributor
good pick, actually its a typo. it should be "terminate the workflow instance." But thanks for the example code