Looking at the Datastore Inventory in the VI client, there is a "Number of Virtual Machines:" under the General information of the Summary tab...I am looking for a script that will retrieve that information for me....
I started the script but I get stuck...I am very new to this...
Get-Datastore | where-object {$_.name -like "wlp"} #this gives me all the datastores that are not local
Could anyone provide some insight on how to script to retrieve the number of virtual machines on the datastores...
Thank you, Lee
This should do what you want:
Get-Datastore | where {$_.Name -like "wlp*"} | Sort-Object -Property Name | %{$_ | select @{N="DSname"; E={$_.Name}}, @{N="VMcount";E={(Get-VM | Measure-Object).count}}}
That gives me the total number of virtual machines for my environment, 473, for each datastore.
DSname VMcount
WLP_RIC_DEV_2038_001 473
WLP_RIC_DEV_2038_002 473
WLP_RIC_DEV_2038_003 473
WLP_RIC_DEV_2038_004 473
WLP_RIC_DEV_2038_005 473
Etc.....
How do I get the total for each datastore?
Currently, my datastores reflect this within the VI client:
WLP_RIC_DEV_2038_001 - 17
WLP_RIC_DEV_2038_002 - 23
WLP_RIC_DEV_2038_003 - 21
WLP_RIC_DEV_2038_004 - 29
WLP_RIC_DEV_2038_005 - 15
Etc..
Sorry, something went wrong with the cut-and-paste
Get-Datastore | where {$_.Name -like "vmfs*"} | Sort-Object -Property Name | %{$_ | select @{N="DSname"; E={$_.Name}}, @{N="VMcount";E={($_ | Get-VM | Measure-Object).count}}}
PERFECT...
Thank you LucD