HI,
I am connected to multiple vcenters where we have some VM objects that have the same name (no duplicates in the same vcenter).
and I need to run a get-vm while connected to the 2 vcenters and store that in a variable $vms
it is always the case for VMs with the same name that if a VM is powered on in one vcenter, it is powered off in the other vcenter. (DR)
for those VMs in that case, I need my variable to store the VM object that is powered on AND ignore the powered off ones... for other VMs, I need powered on and powered off vms to be listed.
here is what i am doing but it is not working
$vms = (get-vm | ForEach-Object {
if($_.name -eq $null){
$_ = ($_ | Where-Object {$_.powerstate -eq "poweredon"}) }else{$_}
})