
This script can be used to check whether user’s disk partitions contain the correct 4KB alignment. Over the next few years, data storage will transition from physical format of hard disk drives that are in 512-byte sectors to 4,096-byte sectors (also known as 4K or 4KB sectors) hard disk drives. This change includes increases in storage density and reliability. Many customers have to know whether their disk partitions have the non-4kb alignment issues which can cause incompatibility issues with existing software (including operating systems and applications).
We can use Test-OSC4kAligned function to check whether user’s disk partitions contain the correct 4kb alignment.
This script contains the Format-OSCResult and Test-OSC4kAligned functions. Format-OSCResult
is an internal function to provide a formatter operation for Test-OSC4kAligned. You can use them in following ways:
Method 1:
Method 2:
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
#Get disk drives
$diskDrives = Get-WmiObject -Class Win32_DiskDrive
#foreach disks
foreach($diskDrive in $diskDrives)
{
#Convert disk drive to disk partition
$deviceID = $diskDrive.DeviceID -replace "\\","\\"
$diskPartitions = Get-WmiObject -Query "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=`"$deviceID`"} `
WHERE AssocClass=Win32_DiskDriveToDiskPartition"
foreach($diskPartition in $diskPartitions)
{
$is4kAligned = ($diskPartition.StartingOffset % 4096) -eq 0
$name = $diskPartition.Name
$partitionSize = "{0:0.00}" -f ($diskPartition.Size /1GB)
$description = $diskPartition.Description
#Convert disk partition to logical disk
$query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=`"$($diskPartition.DeviceID)`"} `
WHERE AssocClass=Win32_LogicalDiskToPartition"
$logicalDisks = Get-WmiObject -Query $query
foreach($logicalDisk in $logicalDisks)
{
$deviceID = $logicalDisk.DeviceID
$diskSize = "{0:0.00}" -f ($logicalDisk.Size /1GB)
$deviceInfoList += Format-OSCResult $is4kAligned $name $deviceID $diskSize $partitionSize $description
}
}
}
#Get disk drives $diskDrives = Get-WmiObject -Class Win32_DiskDrive #foreach disks foreach($diskDrive in $diskDrives) { #Convert disk drive to disk partition $deviceID = $diskDrive.DeviceID -replace "\\","\\" $diskPartitions = Get-WmiObject -Query "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=`"$deviceID`"} ` WHERE AssocClass=Win32_DiskDriveToDiskPartition" foreach($diskPartition in $diskPartitions) { $is4kAligned = ($diskPartition.StartingOffset % 4096) -eq 0 $name = $diskPartition.Name $partitionSize = "{0:0.00}" -f ($diskPartition.Size /1GB) $description = $diskPartition.Description #Convert disk partition to logical disk $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=`"$($diskPartition.DeviceID)`"} ` WHERE AssocClass=Win32_LogicalDiskToPartition" $logicalDisks = Get-WmiObject -Query $query foreach($logicalDisk in $logicalDisks) { $deviceID = $logicalDisk.DeviceID $diskSize = "{0:0.00}" -f ($logicalDisk.Size /1GB) $deviceInfoList += Format-OSCResult $is4kAligned $name $deviceID $diskSize $partitionSize $description } } }
Example 1: Display help about Test-OSC4kAligned
Command: Get-Help Test-OSC4kAligned
Screenshot:

Example 2: Check if disk partitions are 4kb alignment
Command: Test-OSC4kAligned
Screenshot:

Windows PowerShell 2.0
Technical Resources:
http://support.microsoft.com/kb/2510009