Code snippet – Report with VM name, LUN name, vmdk file and path

This script will write the following information into a .csv file:

.) name of the virtual machine (VM)
.) datacenter name
.) cluster name
.) hard disc
.) datastore name
.) path and name of the .vmdk file

Just fill in the name of your vCenter Server in the first line and edit the path/name of the output file if necessary:

Connect-VIServer vCenter_server_name
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
  ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) { 
    ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
      ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
        "" | Select-Object -Property @{N="VM";E={$VM.Name}},
          @{N="Hard Disk";E={$HardDisk.Name}},
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "C:\VmQuery.csv"

This report will help you with your documentation.

Because if you rename a virtual machine the .vmdk file will not be renamed automatically.

In case of troubleshooting it is sometimes very difficult to find the correct .vmdk files on your storage.

1 Comment

  1. vineeth

    here i need scsi nna also pls help

Leave a Comment

Your email address will not be published. Required fields are marked *