Sorry for a confusing title I'm not too sure how to word it exactly. I'm currently working on a PS Network Status bar GUI. In an effort to try and consolidate some lines and try and make things cleaner, I'm trying to Loop the status checks for my status bars. I have my labels made and if I run everything as individual checks it all works but it ends up being a bunch of repeating lines.
So I am trying to make variables for the checks:
$DC1 = Test-Connection "DC1" -Count 2 -Quiet
$DC2 = Test-Connection "DC2" -Count 2 -Quiet
etc, and then run those into a ForEach loop and then update the appropriate status bar.
$Tests = @("$DC1","$DC2")
ForEach($Test in $Tests){
If($Test -eq $true){
$(($test).Name)StatusLabel.BackColor = "Green"
}
}
I know thats not the right way to do that, but I can't think of a way to add Variable 1 name as part of Variable 2's name