Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to "Continue" in a Process Block?

$
0
0
I can't seem to figure out a way to properly skip the rest of the Process Block without completely exiting it.  Take the following as an example:

function Test
{
	Begin
	{ $i = 1 }

	Process
	{
		if ($i -eq 10) { Write-Error 'Some Error' }
		Write-Host ($i++)
	}
}

cls
1..20 | Test

Write-Error does not terminate the Process block.  However, it doesn't skip the rest of the block as I intend.

Using any keywords such as break, continue, return, or throw will shut down the pipeline completely.

How exactly can I achieve something similar to the effect of "continue" in a loop?


Viewing all articles
Browse latest Browse all 21975

Trending Articles