Dear All,
inside a function I have a loop setup with a foreach statement using a pipe construct.
If a certain condition inside the look is met, I will leave the foreach construct. This works fine using the continue statement. However it seems that not only the foreach statement is interrupted but the function construct also, since the last LogWrite is not executed any more. Here the code :
Normal 0 14 false false false IT ZH-CN X-NONE MicrosoftInternetExplorer4
Function ScanDir
{
LogWrite "Entering in the function"
dir $SourceData\*$filter* | foreach {
$FileOrDirName = $_
if ( $FileOrDirName -match "(IT\d+\S*)\s+(.+)" -eq $true) {
# At least we have the LAM ID , great !!!
$LAM_ID=$matches[1]
$Restline=$matches[2]
LogWrite "Found LAMID: $LAM_ID still to scan: $Restline"
Continue
} else {
# Do something else .....
# some more code should go in here ....
}
LogWrite "Truning back from the function"
}
$MyEntry=Scandir
Any Idea what happens ?
Thank you very much
Yours
Eryk