I'm implementing stretched clusters and would like to know if there is a way to check VMs against the host they are running on and the datastore they are in?
at site 1, all hosts are named xxxx-Axxx, VMs are named A-xxxxxx and datastores are named A-xxxxxx
at site 2, all hosts are named xxxx-Bxxx, VMs are named B-xxxxxx and datastores are named B-xxxxxx
is it possible to check that the VMs named A-xxx are runing on hosts named xxxx-Axx and from datastores named A-xxxxxx, and that that the VMs named B-xxx are runing on hosts named xxxx-Bxx and from datastores named B-xxxxxx?
thanks
You can add a filter using the Where-Object cmdlet:
Get-VM | Sort-Object -Property Name | Select-Object -Property Name,VMHost, @{Name="Datastore";Expression={$_.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[')}} | Where-Object {($_.Name -like "*-A*" -and ($_.VMHost -notlike "*-A*" -or $_.Datastore -notlike "A-*")) -or ($_.Name -like "*-B*" -and ($_.VMHost -notlike "*-B*" -or $_.Datastore -notlike "B-*"))}
The following PowerCLI script will return a list of all VM's, the hosts they are running on and the datastores where their vmx file is located:
Get-VM | Sort-Object -Property Name | Select-Object -Property Name,VMHost, @{Name="Datastore";Expression={$_.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[')}}
thanks for the reply.
I got as far as that, but i was hoping to be able to check that the VM named A-xxxxx is running on a host called xxxx-Axxxx and is located in a datastore called A-xxxxx and only if those rules don't match then alert me.
any idea if that can be done?
thanks
You can add a filter using the Where-Object cmdlet:
Get-VM | Sort-Object -Property Name | Select-Object -Property Name,VMHost, @{Name="Datastore";Expression={$_.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[')}} | Where-Object {($_.Name -like "*-A*" -and ($_.VMHost -notlike "*-A*" -or $_.Datastore -notlike "A-*")) -or ($_.Name -like "*-B*" -and ($_.VMHost -notlike "*-B*" -or $_.Datastore -notlike "B-*"))}
that is excellent. thank you very much.
only needed one small change and ended up with this:
$body = Get-VM |
Sort-Object -Property Name |
Select-Object -Property Name,VMHost,
@{Name="Datastore";Expression={$_.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[')}} |
Where-Object {($_.Name -like "A-*" -and ($_.VMHost -notlike "*-A*" -or $_.Datastore -notlike "A-*")) -or ($_.Name -like "B-*" -and ($_.VMHost -notlike "*-B*" -or $_.Datastore -notlike "B-*"))}
thanks again.