PowerShell for Windows Admins

Jun 23 2011   12:46PM GMT

Testing the 4K boundary

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Advanced Format disks have started shipping –see http://managedux.com/2011/04/26/using-vbscript-to-check-partitions-for-advanced-format-4k-512e-sector-alignment/

These disks use a 4096 byte sector instead of 512. To get the best performance from these disks the partitions have to be aligned to a 4K boundary. This happens automatically in Windows 2008 and above. 

We need to be able to start testing partition alignment. This function uses a couple of WMI classes to do just that.

function test-4KAligned {
[CmdletBinding()]
param (
   [string]$computer=".",
  
   [ValidatePattern("[A-Z]:")]
   [string]$drive
)

PROCESS{
$partitions = Get-WmiObject -Class Win32_DiskPartition -ComputerName $computer

foreach ($partition in $partitions){
 
  $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=’$($partition.DeviceID)’} WHERE AssocClass=Win32_LogicalDiskToPartition"
  $disktopart = Get-WmiObject -ComputerName $computer -Query $query
 
 
if (($partion.StartingOffset % 4096) -eq 0){
   $align = $true
}
else {
   $align = $false
}
 
$diskpartition = New-Object -TypeName PSObject -Property @{
   Partition = $partition.Name
   Description = $partition.Description
   AlignedTo4Kboundary = $align
   Drive = $disktopart.DeviceID
}
if ($drive) {
   if ($drive -eq $diskpartition.Drive){$diskpartition}
}
else {$diskpartition}
}

}#process

<#
.SYNOPSIS
Tests disk partition alignment to 4k boundary

.DESCRIPTION
Tests disk partition alignment to 4k boundary.
See
http://managedux.com/2011/04/26/using-vbscript-to-check-partitions-for-advanced-format-4k-512e-sector-alignment/
and
http://msdn.microsoft.com/en-us/library/hh182553.aspx

Default is that all drives are tested

.PARAMETER  computer
Computer to test

.PARAMETER  drive
Drive to test

.EXAMPLE
test-4kaligned

Tests local machine

.EXAMPLE
test-4kaligned -computer server01

Tests remote machine

.EXAMPLE
test-4kaligned -computer server01 -drive C:

Tests C: drive on remote machine

#>

}

The test is performed using modulus arithmetic on the starting offset. A result of zero means its divisible exactly by 4096 so is aligned.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: