Needed to dismount some datastores/ LUNs from a few hosts but before doing that needed to ensure none of the VMs running on these datastores are hosted on the hosts I want to remove access from. This one-liner PowerCLI will do just that for you:
1 |
Get-Datastore | ?{ $_.Name -match "PP_" } | Get-VM | ft Name,VMHost |
Replace “PP_” with the pattern you are interested in matching in the datastore name.
A variation of the above where I only list VMs that are hosted the hosts I want to remove access from:
1 |
Get-Datastore | ?{ $_.Name -match "PP_" } | Get-VM | ?{ $_.VMHost -notmatch "0[1-3]" } | ft Name,VMHost |
In my case the hosts that should have access to the datastores with a “PP_” in their name will also have numbers 01-03 in them. Any VMs not on hosts with these names are what I am interested in.