Audit for Disk Offset

Unaligned disks, particularly in a consolidated VM environment, can result in some serious storage performance problems. So, how about we query all our Windows VMs for their existing offset values?

The first step is to collect what machines to audit. If you have the VMware tools installed and if all your VMs are Windows, it can be as easy as:

Connect-viserver <VCENTER>

$Servers = get-vm

The information we need is in the win32_diskpartition WMI namespace. The following collects the pertinent information for each server and puts the results in an array.

$Results = @()
$Errors = @()

foreach ($Server in $Servers) {   
    If (Test-Connection -computername $Server -quiet) {
        $DiskPartitions = get-wmiobject -query "Select systemname,blocksize,startingoffset,name,index from win32_diskpartition" -computername $server -ea SilentlyContinue
        if (!$?) {
            $errors += $Server
            Write-Host "Error: $Server — unable to bind to WMI." -foregroundcolor Red
        } Else {
            $Results += $DiskPartitions
    } Else {
        $errors += $Server
        Write-Host "Error: $Server — unable to ping." -foregroundcolor Red

First we initialize two arrays for results and errors. Then we enter a foreach loop. We use test-connection to make sure the server is pingable. If it is, we get our WMI information.

The if (!$?) is another error check. $? is a variable that is set true when the previous command executed successfully. If the previous command did not, it will be set false. “!” is an alias for not. So, essentially, we are checking to see if the last command failed. If it did, we write an error to the screen and add the server to our array of errors. If it succeeded, we add the WMI results to our results array.

The next step is to export our data. Generally, I find this to get the job done:

$Results | Select systemname,blocksize,startingoffset,name,index | export-csv “Results.csv” -notypeinformation
$errors | out-file "Failed.txt"

this will give you two files, one a csv of all the wmi information, the other a list of servers that we failed to collect information for.


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 )

Google+ photo

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

Connecting to %s