Some time ago I  already created a script to report the disk alignment status of your Windows VM’s. I updated the script so you are able to export it to a CSV or XML file.

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

foreach($vm in $vms){
$wmi = get-wmiobject -class "Win32_DiskPartition" `
-namespace "root\CIMV2" -ComputerName $vm            

    foreach ($objItem in $wmi){
        $Details = "" | Select-Object VMName, Partition, Status        
            if ($objItem.StartingOffset -eq "65536"){
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition aligned"
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition NOT aligned"                    
    $myCol += $Details
$myCol | Export-Csv -NoTypeInformation "C:\Temp\PartitionAlignment.csv"
#$myCol | Export-Clixml "C:\Temp\PartitionAlignment.xml"

The script uses WMI to gather the information about the partition of the Windows VM. So if you’re using a Firewall, be sure to open the right ports. More info about WMI and Firewalls, can be found over here:

The output will look like this:



11 thoughts on “PowerCLI: Check Partition Alignment (Windows VMs Only)

  1. The fact that a partion doesn’t start at offset 65536 doesn’t mean it is not aligned. Windows 2008 leaves the fist megabyte of the disk unused. This is still an aligned situation although your script will say it’s not. To really make sure a disk is aligned use the instruction from the following article:

    In short: Issue the following command on the client:
    wmic partition get BlockSize, StartingOffset, Name, Index
    and then
    fsutil fsinfo ntfsinfo c:
    you can use any other drive letter ofcourse.

    Divide the StartingOffset from the first command with the “Bytes Per Cluster” from the second command. If the outcome is a integer then the disk is aligned.

    This should all be doable with scripting of course.

  2. The starting offset does not have to be 65536, but it should be divisible by 65536. If you change your if statement to use mod, it will be more accurate.

    if (($Partition.StartingOffset % 65536) -eq 0) {
    $Details.VMName = $objItem.SystemName
    $Details.Partition = $objItem.Name
    $Details.Status = “Partition aligned”

    1. No, it should be divisible by 8192. See the $.01 best practices guide:

      Click to access Perf_Best_Practices_vSphere4.0.pdf

      “The alignment of your file system partitions can impact performance. VMware makes the following
      recommendations for VMFS partitions:
      * Like other disk-based file systems, VMFS suffers a penalty when the partition is unaligned. Using the
      vSphere Client to create VMFS partitions avoids this problem since it automatically aligns the
      partitions along the 64KB boundary.
      * To manually align your VMFS partitions, check your storage vendor’s recommendations for the
      partition starting block. If your storage vendor makes no specific recommendation, use a starting
      block that is a multiple of 8KB.”

    2. I went with if (($partition.startingoffset % 65536) -isnot [decimal]){} .. dividing your offset by 64KB, as long as it’s a whole number is aligned per a number of documents I went off of.

      In your example, startingoffset % 65536 will not always equal zero, for example windows server 2008 aligns at 1024KB (1MB).. or offset 1048576 so yours would = 16.. which is not zero so it would fail as not aligned.

  3. Thanks for the script, I modified it slightly and posted it on my blog – just a quick elseif for another alignment size.

    I spent a good awhile reading your whole site, and I learned a great deal about powercli – many thanks!

  4. Do you know if the WMI call captures info for Dynamic Disks correctly? According to an MS Technet article, WMI calls done locally (using the wmic command) don’t return Dynamic Disk information “reliably.” Not sure if the WMI call done remotely (leveraging PowerCLI as per your article) is any different. As per the MS article:

    Important: Neither the output of the wmic command listed earlier nor any other tool designed only for basic disks reliably reports starting partition offsets of Windows dynamic disks.

    Article located at URL

  5. Inspiret by your script I made one which takes the raid systems block size into account, and check if the disk is aligned to that… Fx windows 2008 has a disk offset of 1048576 which in the above scripts would show the disk as unaligned:

    $vms = get-vm
    $winvms = $vmsview | where {$_.Config.GuestId -match “win”}

    Foreach($winvm in $winvms){$raidblocksize = 64; $wmivm = get-wmiobject -class “Win32_DiskPartition” -namespace “root\CIMV2” -ComputerName $; if($?){Foreach($obj in $wmivm){$a = $obj.StartingOffset/$obj.BlockSize/$raidblocksize; if($a % 2 -eq “0”){$a = “$True”}else{$a = “$false”}$, $obj.Name, $a}}}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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