VM storage information

Share this:

In a data center migration project the storage teams as well as the target VMware team were constantly requesting information for the VMs in each migration group. Along with the basic VM info such as vCPUs, memory, provisioned space, guest OS, they required more details for the VMDKs – datastore, LUN ID of the datastore (since the migration is performed on storage level), SCSI controller and unit number where the disk is attached, etc.

At first sight, RVtools seems like a reasonable choice. It provides plenty of information and is easy to use. However there are a few caveats:

  • Manual work to sort out only the VMs needed
  • Does not show the SCSI controller number
  • Does not show the LUN IDs of all extents, composing single datastore

I wanted to minimize the time spent on generating the reports, so I decided to build custom PowerCLI script specific for my needs. Here is the result:

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

$vCenter = Read-Host -prompt "Enter vCenter Server instance"

Connect-VIServer -server $vCenter

$CSVObjects = @()
$destpath = [Environment]::GetFolderPath("Desktop")

$vms = Get-VM -Location esxi01.vlab.local | sort Name #Edit to match your requirements -Location, -Name etc.

foreach($vm in $vms){
	
	foreach ($harddisk in $vm.ExtensionData.Config.Hardware.Device | Where {$_.DeviceInfo.Label -like "Hard Disk*"}) {
	$hd = Get-HardDisk -VM $vm -Name $harddisk.DeviceInfo.Label
	
	$CSVObject = new-object PSObject
	$CSVObject | add-member -membertype NoteProperty -name "VM" -value $vm.Name
	$CSVObject | add-member -membertype NoteProperty -name "vCPUs" -value $vm.NumCPU
	$CSVObject | add-member -membertype NoteProperty -name "Memory MB" -value $vm.MemoryMB
	$CSVObject | add-member -membertype NoteProperty -name "HardDisk" -value $hd.Name
	$CSVObject | add-member -membertype NoteProperty -name "Size GB" -value $hd.CapacityGB
	$CSVObject | add-member -membertype NoteProperty -name "Path" -value $hd.FileName
	$hdcontroller = Get-ScsiController -HardDisk $hd
	$CSVObject | add-member -membertype NoteProperty -name "Controller" -value $hdcontroller.Name
	$CSVObject | add-member -membertype NoteProperty -name "Unit Number" -value $harddisk.UnitNumber
	$contrdev = $vm.ExtensionData.Config.Hardware.Device | Where {$_.DeviceInfo.Label -eq $hdcontroller.Name}
	$CSVObject | add-member -membertype NoteProperty -name "Controller Type" -value $contrdev.DeviceInfo.Summary
	$dsname=$hd.FileName.Split("]")[0].TrimStart("[")
	$CSVObject | add-member -membertype NoteProperty -name "Datastore" -value $dsname
	$ds = Get-Datastore -Name $dsname
	$ddisks=$ds.ExtensionData.Info.VMFS.Extent | select DiskName
	$diskid=""
	foreach ($dsk in $ddisks){
		$diskid+=$dsk.DiskName
		$diskid+=";"
	}
	$CSVObject | add-member -membertype NoteProperty -name "LunID" -value $diskid
	$CSVObject | add-member -membertype NoteProperty -name "OS" -value $vm.ExtensionData.Config.GuestFullName
	$CSVObject | add-member -membertype NoteProperty -name "Path to VMX" -value $vm.ExtensionData.Summary.Config.VmPathName
	
	$CSVObjects += $CSVObject
	
	}

}

Disconnect-VIServer -Confirm:$False

$CSVObjects | Export-Csv -Path $destpath\VMinfo.csv -NoTypeInformation

The script will export .csv on your Desktop with the following information: VM, vCPUs, Memory MB, HardDisk, Size GB, Path, Controller, Unit Number, Controller Type, Datastore, LunID, OS, Path to VMX.

Now the manual work is minimized only to put the VM names which I need.

Your ideas and comments are welcome!

The following two tabs change content below.

Ivaylo Ivanov

Ivaylo has 5 years of professional IT experience. Most of it in server administration area, network and virtualization technologies. From 2014 he specializes in VMware products family. He holds VCIX6-DCV and VCP7-CMA certifications. vExpert 2016/2017

Latest posts by Ivaylo Ivanov (see all)

About Ivaylo Ivanov

Ivaylo has 5 years of professional IT experience. Most of it in server administration area, network and virtualization technologies. From 2014 he specializes in VMware products family. He holds VCIX6-DCV and VCP7-CMA certifications. vExpert 2016/2017
Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.