PowerCLI: Check Partition Alignment (Windows VMs Only)

image

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"
            }
            else{
                $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: http://msdn.microsoft.com/en-us/library/aa822854%28VS.85%29.aspx

The output will look like this:

image


8 Responses to PowerCLI: Check Partition Alignment (Windows VMs Only)

  1. Pingback: Tweets die vermelden PowerCLI: Check Partition Alignment (Windows VMs Only) « ICT-Freak.nl -- Topsy.com

  2. Pingback: uberVU - social comments

  3. Vincent says:

    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: http://msdn.microsoft.com/en-us/library/dd758814.aspx

    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.

  4. Pingback: Virtualization Short Take #34 - blog.scottlowe.org - The weblog of an IT pro specializing in virtualization, storage, and servers

  5. NotoriousBDG says:

    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”
    }

  6. Pingback: PowerCLI - Windows VM Partition Alignment | Alex Feigenson's Blog

  7. 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!

  8. Daniel M (@dmVI) says:

    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 http://msdn.microsoft.com/en-us/library/dd758814.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>