Automation

 View Only
  • 1.  HELP - How to get the number of virtual machines on a datastore?

    Posted Jun 03, 2009 03:34 PM

    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



  • 2.  RE: HELP - How to get the number of virtual machines on a datastore?

    Posted Jun 03, 2009 03:47 PM

    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}}}
    



  • 3.  RE: HELP - How to get the number of virtual machines on a datastore?

    Posted Jun 03, 2009 04:04 PM

    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?



  • 4.  RE: HELP - How to get the number of virtual machines on a datastore?

    Posted Jun 03, 2009 04:05 PM

    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..



  • 5.  RE: HELP - How to get the number of virtual machines on a datastore?
    Best Answer

    Posted Jun 03, 2009 05:18 PM

    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}}}
    



  • 6.  RE: HELP - How to get the number of virtual machines on a datastore?

    Posted Jun 03, 2009 06:13 PM

    PERFECT...

    Thank you LucD