PowerCLI

 View Only
  • 1.  List ESX HostName and datastores

    Posted Jan 24, 2014 09:01 PM


    HI

    Does anyone have a script to list the host name and all datstores that the host is using?



  • 2.  RE: List ESX HostName and datastores

    Posted Jan 24, 2014 09:02 PM

    get-vmhost | get-datastore



  • 3.  RE: List ESX HostName and datastores

    Posted Jan 24, 2014 09:02 PM

    or you could add:

    get-vmhost -name esxihostname | get-datastore



  • 4.  RE: List ESX HostName and datastores

    Posted Jan 24, 2014 09:37 PM

    how could i import a list of host names and export the output to a csv file?

    Thanks



  • 5.  RE: List ESX HostName and datastores

    Posted Jan 24, 2014 10:24 PM

    import-csv -path c:\filepath\filename.csv | %{get-vmhost -name $_.name} | get-datastore | export-csv -path "c:\somepath\somefilename.csv" -notypeinformation -useculture



  • 6.  RE: List ESX HostName and datastores

    Posted Jan 27, 2014 02:31 PM

    I'm getting the following error:

    "Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null

    or empty. Supply an argument that is not null or empty and then try the comman

    d again.

    At Test\ESX\Get-ESX-DS.ps1:17 char:42

    + import-csv hosts.csv | %{get-vmhost -name <<<<  $_.name} | get-datastore | ex

    port-csv ESX-Datastore.csv -notypeinformation -useculture

        + CategoryInfo          : InvalidData: (:) [Get-VMHost], ParameterBindingV

       alidationException

        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

    ation.ViCore.Cmdlets.Commands.

    GetVMHost"



  • 7.  RE: List ESX HostName and datastores

    Posted Jan 27, 2014 02:55 PM

    I think this has to do with how your Csv is formatted. In the first row of your Csv try putting the word name so it knows that this column should be associated with the $._name statement.

    I.e.:

    "Name"

    "Esxihost1"

    "Esxihost2"



  • 8.  RE: List ESX HostName and datastores

    Posted Jan 27, 2014 03:38 PM

    That was it. Everything works except the host name is not being populated in the csv output file.



  • 9.  RE: List ESX HostName and datastores

    Posted Jan 27, 2014 10:30 PM

    It seems like you want to list each ESXi host, and then all of the datastores that are attached to that host.  Here is another approach that does that:

    import-csv -path c:\filepath\filename.csv | %{get-vmhost -name $_.name}

    | select @{N="Name";E={$.name + ","}},@{N="Datastores";E={get-datastore -relatedobject $_ | %{$_.name + "," }}} | export-csv c:\datastores.csv -notypeinformation -useculture