Check Windows Virtual Machines for Partition Alignment
Incorrect virtual machine partition alignment can be the cause of performance issues in a vSphere virtualised environment. Here is a script that will check Windows Virtual Machines to validate if their disk partition alignment is correct as per vendor best practices.
The script will retrieve a list off all powered on VMs from a vCenter server or ESX host. A WMI query will then be performed against each of these servers to retrieve properties from the Win32_DiskPartition class. If the StartingOffset is divisible by 4096, the partition can be considered correctly aligned. All Windows Vista and Windows 2008 or higher guests should have the correct alignment by default. Older desktop and server OSes will not unless an administrator has intervened.
More information on this issue can be found at the VMWare blog here which includes links to the most common storage vendor’s recommendations on this subject.
Powershell 3.0 or higher and VMware PowerCLI are required.
# Add the VMWare PowerCLI cmdlets Add-PSSnapin VMware.VimAutomation.Core # Connect to your vCenter server or ESX host connect-viserver vcenter01 # Create an array of VMs that are currently powered on $colVMs = get-vm | where-object PowerState -eq "PoweredOn" # Perform a WMI query against the VMs using the name property from the array above # -ComputerName accepts an array as the input object which makes this really fast! $wmiQuery = get-wmiobject Win32_DiskPartition -ComputerName $($colVMs).name | select SystemName, Name, Index, BlockSize, StartingOffset # Create a blank array to be able to perform the += operation later on $objOutput = @() # Loop through each result from the WMI query foreach ($wmiResult in $wmiquery) { # If the Starting Offset of the partition is divisible by 4096 the partition is aligned correctly $objAllignmentInteger = ($wmiResult.startingoffset) / 4096 # Build a PSCustomObject for our output including a test for the integer $objResults = [PSCustomObject] @{ "Computer Name" = $wmiResult.SystemName "Disk Name" = $wmiResult.Name "Starting Offset" = $wmiResult.startingoffset "Is Partition Aligned?" = ($objAllignmentInteger -is [uint64]) } # Reset this variable to $null in case it carries over to the next loop $objAllignmentInteger = $null # Add the PSCustomObject to our ouput array $objOutput += $objREsults } # Print the ouput array to the console $objOutput