Checking partition alignment with PowerCLI

Solution 1:

Well, I see you've commented out the line that attempts to do the actual arithmetic. Your code as it is right now says "if partition starting offset = 65536 then partition is aligned".

That's not how it works. Partitions have all sorts of starting offsets. The WMI class returns 2 partitions on my laptop right now, neither of which have a starting offset of 65536.

Secondly, even if you uncommented the line above it, the one where it divides the starting offset by 65536 and compares the remainder to the Decimal data type... that's not how it works either. Don't use the Decimal type.

PS C:\> 1 -Is [Decimal]
False
PS C:\> 1.23 -Is [Decimal]
False

They both evaluate to false. That's not going to tell whether the division resulted in a remainder or not.

Give this a whirl:

Foreach($_ In Get-WMIObject Win32_DiskPartition | Select Name, BlockSize, NumberofBlocks, StartingOffset, @{n='Alignment';e={$_.StartingOffset/$_.BlockSize}}) { $_ }

Name           : Disk #0, Partition #0
BlockSize      : 512
NumberofBlocks : 614400
StartingOffset : 1048576
Alignment      : 2048

Name           : Disk #0, Partition #1
BlockSize      : 512
NumberofBlocks : 487778304
StartingOffset : 315621376
Alignment      : 616448

If Alignment is a whole number, you're good. If it's a decimal, alignment is wrong.

Here's a good article on partition alignment:

http://technet.microsoft.com/en-us/library/dd758814(v=SQL.100).aspx

By the way, this is not something you typically need to worry about on Windows 2008+ VMs. Windows can handle its own partition alignment. Windows 2003 and below, maybe.