I have a foreach loop on a variable that also contains and array of data. Whats the best way to loop through the first set of data and then foreach item in the next set to do somethings.
so kinda like
foreach ($Item in $Data){
if ($Item.Value -eq "Names"){
foreach($name in $Item.Value.Names){
Do-Something .....
}
}
}
Cool, thanks Don. Following on from this. If i wanted the script to execute different commands based on the value $Item.Value. What would be the best way.
I suppose i could use loads of Try statements, maybe something like this…
foreach ($Item in $Data){
try {
if ($Item.Value -eq "Names"){
foreach($name in $Item.Value.Names){
Do-Something .....
}
}
}
Catch{
Do-Something
}
try {
if ($Item.Value -eq "Something"){
foreach($Something in $Item.Value.Something){
Do-Something .....
}
}
}
catch {
Do-Something
}
elseif {
Do-Something
}
}