
This script can be used to check whether a user’s disk partitions contain the correct 4KB alignment. Over the next few years, data storage will transition from a 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 the Check4kAligned function to check whether user’s disk partitions contain the correct 4kb alignment.
This script contains the Check4kAligned and MMod functions. MMod is an internal function to provide support for Check-OSC4kAligned. You can use them in following ways:
Method:
1.Download the script and copy it to your computer.
2.Press the “Windows” key to open the “Start” menu and type “cmd” in the “Search
programs and files” text box.
3.Right-click “cmd.exe” and select “Run as administrator” item to open “Command Prompt”

Note: For Windows 8, press the “Windows” key and “X” key together to show a menu. Click the “Command Prompt (Admin)” option.
4.Use the console script host to run your script:
cscript.exe “filepath\scriptname.vbs”
For example: cscript.exe "C:\Users\TestUser\Desktop\Check4kAligned\Check4kAligned.vbs"
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.
'for each disks
For Each diskDrive In diskDrives
'Convert disk drive to disk partition
Set diskPartitions = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
Replace(diskDrive.DeviceID,"\","\\") & """} WHERE AssocClass = " & _
"Win32_DiskDriveToDiskPartition")
For Each diskPartition In diskPartitions
is4kAligned = False
If (MMod(diskPartition.StartingOffset,4096) = 0) Then
is4kAligned = True
End If
name = diskPartition.Name
'Convert Byte to GB and save as 2 decimal places: 0.00
partitionSize = FormatNumber(diskPartition.Size / 1073741824,,,,0)
description = diskPartition.Description
'Convert disk partition to logical disk
Set logicalDisks = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
diskPartition.DeviceID & """} WHERE AssocClass = " & _
"Win32_LogicalDiskToPartition")
If logicalDisks.Count =0 Then
deviceID = ""
diskSize = 0
outputMsg = outputMsg + FormatResult(is4kAligned,name,deviceID,diskSize,partitionSize,description)
End If
For Each logicalDisk In logicalDisks
deviceID = logicalDisk.DeviceID
diskSize = FormatNumber(logicalDisk.Size / 1073741824,,,,0)
outputMsg = outputMsg + FormatResult(is4kAligned,name,deviceID,diskSize,partitionSize,description)
Next
Next
Next
'for each disks For Each diskDrive In diskDrives 'Convert disk drive to disk partition Set diskPartitions = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _ Replace(diskDrive.DeviceID,"\","\\") & """} WHERE AssocClass = " & _ "Win32_DiskDriveToDiskPartition") For Each diskPartition In diskPartitions is4kAligned = False If (MMod(diskPartition.StartingOffset,4096) = 0) Then is4kAligned = True End If name = diskPartition.Name 'Convert Byte to GB and save as 2 decimal places: 0.00 partitionSize = FormatNumber(diskPartition.Size / 1073741824,,,,0) description = diskPartition.Description 'Convert disk partition to logical disk Set logicalDisks = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _ diskPartition.DeviceID & """} WHERE AssocClass = " & _ "Win32_LogicalDiskToPartition") If logicalDisks.Count =0 Then deviceID = "" diskSize = 0 outputMsg = outputMsg + FormatResult(is4kAligned,name,deviceID,diskSize,partitionSize,description) End If For Each logicalDisk In logicalDisks deviceID = logicalDisk.DeviceID diskSize = FormatNumber(logicalDisk.Size / 1073741824,,,,0) outputMsg = outputMsg + FormatResult(is4kAligned,name,deviceID,diskSize,partitionSize,description) Next Next Next
Example 1: Check if disk partitions are 4kb alignment
Command: cscript.exe "C:\Users\TestUser\Desktop\Check4kAligned\Check4kAligned.vbs"
Screenshot:

Technical Resources: