$TestArray1="a","b","c"
$TestArray2="ab","ac","abc"
$TestArray3="abd","abe","acd","ace"
$TestArray = @($TestArray1,$TestArray2,$TestArray3)
0..2 | % { # Loop 1
"command1 $_"
"command2 $_"
$IsOk=$True
$TestArray[$_] | % { # Loop2
If ( $_ -contains 'abc' ) { $IsOK=$False }
}
IF ($IsOK)
{
"command3 $_"
"command4 $_"
}
}
On the first pass through loop 1 it uses TestArray1 to check variable and does command 3 & 4
On the second pass through loop 1 it uses TestArray2 to check variable and does not do commands 3 &4
On the third pass through loop 1 it uses TestArray3 to check variable and does command 3 &4
Here is output
command1 0
command2 0
command3 0
command4 0
command1 1
command2 1
command1 2
command2 2
command3 2
command4 2
-
Edited by
Brian Nadjiwon
2 hours 22 minutes ago