Checking Disk alignment with Powershell

Disk alignment has been well discussed on the web and the methods to check this always seem to use wmic or DISKPART. I’ve always loathed wmi so here’s a few lines of Powershell that achieves the same thing;

?View Code POWERSHELL
$sqlserver = "sqlinstance";
# Get disk partitions
$partitions = Get-WmiObject -ComputerName $sqlserver -Class Win32_DiskPartition;
$partitions | Select-Object -Property DeviceId, Name, Description, BootPartition, PrimaryPartition, Index, Size, BlockSize, StartingOffset | Format-Table -AutoSize;

This will display something looking like below;

DeviceId              Name                  Description             BootPartition PrimaryPartition Index          Size BlockSize StartingOffset
--------              ----                  -----------             ------------- ---------------- -----          ---- --------- --------------
Disk #2, Partition #0 Disk #2, Partition #0 Installable File System         False             True     0 1099523162112       512        1048576
Disk #3, Partition #0 Disk #3, Partition #0 Installable File System         False             True     0  536878252032       512        1048576
Disk #4, Partition #0 Disk #4, Partition #0 Installable File System         False             True     0    1082130432       512          65536
Disk #5, Partition #0 Disk #5, Partition #0 Installable File System         False             True     0    1082130432       512          65536
Disk #1, Partition #0 Disk #1, Partition #0 Installable File System         False             True     0  107376279552       512        1048576
Disk #0, Partition #0 Disk #0, Partition #0 Installable File System          True             True     0     104857600       512        1048576
Disk #0, Partition #1 Disk #0, Partition #1 Installable File System         False             True     1   81684070400       512      105906176
Disk #0, Partition #2 Disk #0, Partition #2 Installable File System         False             True     2  104857600000       512    81789976576
Disk #0, Partition #3 Disk #0, Partition #3 Installable File System         False             True     3  104857600000       512   186647576576

A 64K cluster size is good for SQL Server. But what about the offset? The simple calculation below can be used to check this…

StartingOffset / BlockSize / 128 (a 64K cluster has 128 sectors assuming a 512 block size).

If this calculation spits out a number with any decimal places then you have some disk aligning to do.


7 Comments

  1. Perry Whittle says:

    Mmm, call me Mr Synical but that output is more or less no different to the output from wmic and wmic doesn’t require Powershell to be installed. IMHO nothing wrong with WMI, in fact isn’t WMI the background of Powershell processes anyway

  2. Rhys says:

    Hi Perry,

    Yeah, it’s not meant to be different really output wise. You may prefer wmi but you’re certainly in the minority. Moving forward Powershell will become ubiquitous while wmic will not. You still using betamax too? 😉

    Cheers,

    Rhys

  3. Perry Whittle says:

    Betamax? Good god man, i’m not as advanced as that 😀
    As I said previously isn’t Powershell just the cmdlet shell for COM\WMI access?

    Regards

    Perry

  4. Rhys says:

    Hi Perry,

    No, it’s much more than that. It’s built on top of the .Net framework but does provide access to COM/WMI as well (but in a much more user-friendly way IMHO). It should be on the cv of every IT professional. Check it out.

    Rhys

  5. Perry Whittle says:

    Rhys

    yes, i have dabbled with some Powershell already, its ok but i’m not getting over excited about it just yet. Although it is a little more user friendly its still just basically a front end vehicle for COM\WMI access and i cant see wmic disappearing anytime soon, in fact, microsoft still reference it in their SQL Server alignment best practices doc and not a PS command 😉
    I was just a bit confused when you said you loathed wmi when that’s all Powershell is essentially is a user friendly front end

    Regards

    Perry

  6. Rhys says:

    It’s really not just a front-end for WMI/COM (.Net fw I mentioned).

    Cheers,

    Rhys

  7. iHunger says:

    It was a little funny to see “I’ve always loathed wmi” followed by the PowerShell cmdlet “Get-WmiObject” – but I understand what you mean – PowerShell makes working with WMI and .Net objects much easier.

    I agree with Rhys that PowerShell is much more than a front-end for WMI/COM. It looks like PowerShell automation shows up for all new releases of Microsoft’s product suites.

Leave a Reply