Checking partition alignment in vCenter using Powershell

A quick PowerCLI and Powershell script to check the partition alignment of Windows guests in a specific VM cluster under VMWare.

More information in the importance of partition alignment on hosts using storage arrays can be found at the following links:

NetApp – Best Practices for File System Alignment in Virtual Environments
Aligning your VMs virtual hard disks
Current Status, An Update, and a Look to the Future of Alignment

Good luck!

Connect-VIServer  myserver.fqdn.com
$Cluster = (Read-Host "Enter cluster name")

$myCol = @()
$vms = Get-Cluster $Cluster | get-vm | where {$_.PowerState -eq "PoweredOn" -and `
$_.Guest.OSFullName -match "Microsoft Windows*" } | Sort Name 

foreach($vm in $vms){
try {
$wmi = get-wmiobject -class "Win32_DiskPartition" `
-namespace "root\CIMV2" -ComputerName $vm            
	foreach ($objItem in $wmi){
        $Details = "" | Select-Object VMName, Partition, StartingOffset ,Status
		if ($objItem.StartingOffset) {
		$Details.StartingOffset = $objItem.StartingOffset
		$objItem.StartingOffset = $objItem.StartingOffset / 4096
#				Write $objItem.StartingOffset.gettype().name
            if ($objItem.StartingOffset.gettype().name -eq "UInt64"){
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition aligned"
            }
            else{
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition NOT aligned"
            }
    $myCol += $Details
    }
	}
}
catch {
Write "Error... "; $Error[0]
}
$myCol 
}