Using the below code I'm trying to find servers that have mismatching power status in our SQL database (manually entered, so prone to mistakes) and vCenter. I doesn't quite work though since at -And $VM.PowerState -like "PoweredOn" it gets the status of all servers (about 500) rather than just one server at a time, causing the statement to always fail.
# $VM = List of Virtual Machines, properties Name and PowerState
# $ServerList = List of Servers, properties Name and Status.
foreach ($serverEntry in $ServerList) {
if ($VM.Name -contains $serverEntry.Name -And $VM.PowerState -like "PoweredOn" -And $serverEntry.Status -like "In Use") {
Stuff will happen
} else {
Some other stuff
}
}
I tried a nested loop but can't get that to work, and since the servers aren't listed in the same order I can't use a simple counter ($i).
How do I solve this?