VMware Cloud Community
vmhyperv
Contributor
Contributor
Jump to solution

List of VMs residing on Datastore,ESXi and Cluster

Hello,

   I have list of 40 server in csv like VM1,VM2,.....VM40. We need to findout these VM resides on which ESXi host,Datastore and Cluster name using import function.Any help on this really appreaciated.

thanks

vmk

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If you change the last line of the script into:

} | Export-CSV -Path VMsReport.csv -NoTypeInformation -UseCulture

then you will save the output as a .csv file called VMsReport.csv.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If you have  a .csv file called VMs.csv. that has a header row with a column header "VM", like:

VM

VM1

VM2


then you can get the ESX host, cluster and datastores of the VM's in the .csv file with:

Import-Csv -Path VMs.csv | ForEach-Object {
  Get-VM -Name $_.VM | Select-Object -Property Name,VMHost,
  @{N="Cluster";E={$_.VMHost.Parent}},
  @{N="Datastores";E={[string]::Join(',',($_|Get-Datastore))}}
}

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
vmhyperv
Contributor
Contributor
Jump to solution

Robert,

   Can you modify a little bit to  gereate the out put in csv format.

thanks

vmk

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If you change the last line of the script into:

} | Export-CSV -Path VMsReport.csv -NoTypeInformation -UseCulture

then you will save the output as a .csv file called VMsReport.csv.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

Robert,

   I did but its taking little bit more time to generate report.

Import-Csv -Path C:\VMs.csv | ForEach-Object {
  Get-VM -Name $_.VM | Select-Object -Property Name,VMHost,
  @{N="Cluster";E={$_.VMHost.Parent}},
  @{N="Datastores";E={[string]::Join(',',($_|Get-Datastore))}}
} | Export-Csv "C:\Vm-datastore.csv" -noTypeInformation

thanks

vmk

0 Kudos