Featured image of post Script - PowerCLI VM Disk Report

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.

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.

Workload SCSI ID Datastore
OS 0:0 Datastore 01
SQL System Root 0:1 Datastore 01
SQL Temp 1:0 Datastore 02
SQL User DB 2:0 Datastore 03
SQL User LOG 3:0 Datastore 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.

Built with Hugo
Theme Stack designed by Jimmy