Script – PowerCLI VM Disk Report

Recently I had to create VMware vSphere VMs with a whole bunch of virtual disks. The application running inside of the virtual machines required a special disk layout and placement of the disks to guarantee optimal performance. To make sure everything is fine, I created a PowerCLI VM Disk Report to verify the configuration of the vSphere VMs.

A simple example of an application that benefits of a special disk layout and placement of the disks is a basic Microsoft SQL Server. Placing “User DB” and “User LOG” on separate drives allows the I/O activity to occur at the same time for both the data and log files.

WorkloadSCSI IDDatastore
OS0:0Datastore 01
SQL System Root0:1Datastore 01
SQL Temp1:0Datastore 02
SQL User DB2:0 Datastore 03
SQL User LOG3:0Datastore 04

The VM Disk Report enables you to verify the location of each disk and the configured SCSI ID of the virtual machine.

PowerCLI VM Disk Report

PowerCLI VM Disk Report

Actually, the Get-VMDisk function is very simple, it is more or less an optimized representation of disk properties. But since I need this report very often, a PowerShell function that is stored inside of my profile makes absolute sense to me.

function Get-VMDisk {

[CmdletBinding()]
    param( 
        [Parameter(Mandatory=$True, ValueFromPipeline=$True, Position=0, HelpMessage = "VMs to process")]
        [ValidateNotNullorEmpty()]
        	[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]] $myVMs
    )
Process {
        $View = @()
        foreach ($myVM in $myVMs){
            $VMDKs = $myVM | get-HardDisk
            foreach ($VMDK in $VMDKs) {
                if ($VMDK -ne $null){
                    [int]$CapacityGB = $VMDK.CapacityKB/1024/1024
                    $Report = [PSCustomObject] @{
                            Name = $myVM.name 
                            PowerState = $myVM.PowerState
                            Datastore = $VMDK.FileName.Split(']')[0].TrimStart('[')
                            VMDK = $VMDK.FileName.Split(']')[1].TrimStart('[')
                            StorageFormat = $VMDK.StorageFormat
                            CapacityGB = $CapacityGB
                            Controller = $VMDK.ExtensionData.ControllerKey -1000
                            Unit = $VMDK.ExtensionData.UnitNumber
                        }
                        $View += $Report
                    }   
                }
            }
    $View | Sort-Object VMname, Controller, Unit
    }
}

Note:
The function will not work for IDE disks. There may be other disk types in future vSphere versions (e.g. NVMe) that will not work with this.

Robert van den Nieuwendijk wrote a great PowerShell script to get a report covering which SCSI ID maps to the Windows drive letters. For Linux based operating systems I typically use the command “lsscsi -v” to map the SCSI ID to the disks.

You can also find the latest version of the Get-VMDisk function in my vSphere Modules Github Repository.

Leave a Reply