Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 help and support Forum Windows 8 Forum Vista Tutorials

Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

Vista - Getting the 'cluster size' of your hard disk?


 
 
07-13-2007   #1 (permalink)
Marco Shaw


 

Getting the 'cluster size' of your hard disk?

Is there an easy way to get the cluster size setting on a hard disk?



Couldn't seem to find anything in WMI or in any of the .NET classes...

Marco
My System SpecsSystem Spec
07-13-2007   #2 (permalink)
Hal Rottenberg


 

Re: Getting the 'cluster size' of your hard disk?

On Jul 13, 11:00 pm, Marco Shaw <marco.shaw@_NO_SPAM_gmail.com> wrote:
> Is there an easy way to get the cluster size setting on a hard disk?


Hmm.... I see a few references to win32_Volume, but the class doesn't
exist on my system.

My System SpecsSystem Spec
07-14-2007   #3 (permalink)
Matthias Tacke


 

Re: Getting the 'cluster size' of your hard disk?

Marco Shaw wrote:
> Is there an easy way to get the cluster size setting on a hard disk?
>
> Couldn't seem to find anything in WMI or in any of the .NET classes...
>

Hi Marco,

the hard disk has only a sector size.
Cluster size is a matter of formatting.

Try this:
fsutil fsinfo ntfsinfo c:

HTH

--
Greetings
Matthias
My System SpecsSystem Spec
07-14-2007   #4 (permalink)
Dean Wells \(MVP\)


 

Re: Getting the 'cluster size' of your hard disk?

FWIW, I'm able to get at that info. through WMIC which would almost
certainly indicate it's available through WMI directly -

wmic partition get blocksize

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:eRpRoMcxHHA.2040@TK2MSFTNGP03.phx.gbl...
> Is there an easy way to get the cluster size setting on a hard disk?
>
> Couldn't seem to find anything in WMI or in any of the .NET classes...
>
> Marco



My System SpecsSystem Spec
07-14-2007   #5 (permalink)
Matthias Tacke


 

Re: Getting the 'cluster size' of your hard disk?

Dean Wells (MVP) wrote:
> FWIW, I'm able to get at that info. through WMIC which would almost
> certainly indicate it's available through WMI directly -
>
> wmic partition get blocksize
>

Set seems to return the sector size (512 bytes), not the cluster size which
is by default 4096 bytes on ntfs formatted drives.

--
Greetings
Matthias
My System SpecsSystem Spec
07-14-2007   #6 (permalink)
Dean Wells \(MVP\)


 

Re: Getting the 'cluster size' of your hard disk?

Nod, ... looks like you're right. My apologies, I didn't examine the
results closely enough (FWIW - a bad use of terminology in my opinion;
to me, block is a logical partitioning unit ... c'est la vie.)

Thanks Matthias.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Matthias Tacke" <Matthias@Tacke.de> wrote in message
news:f7amtg$lia$1@news.albasani.net...
> Dean Wells (MVP) wrote:
>> FWIW, I'm able to get at that info. through WMIC which would almost
>> certainly indicate it's available through WMI directly -
>>
>> wmic partition get blocksize
>>

> Set seems to return the sector size (512 bytes), not the cluster size
> which is by default 4096 bytes on ntfs formatted drives.
>
> --
> Greetings
> Matthias



My System SpecsSystem Spec
07-14-2007   #7 (permalink)
Kiron


 

Re: Getting the 'cluster size' of your hard disk?

For those of us that don't have access to win32_Volume.
This is, by no means, a lighting fast solution.

WARNING: Depending on the drive's size, this function takes up to five
minutes per drive, because it reads chkdsk.exe's output to determine the
cluster size. The size is shown in bytes.

function Get-ClusterSize ([char[]]$driveLetter = 'c')
{
$clusterSize = @{}
foreach ($drive in $driveLetter)
{
$drive = $($drive + ':').toUpper()
if (test-path $drive)
{
chkdsk $drive > outPut
$line = (select-string each outPut).line
remove-item outPut
[regex]$rx = '\d+'
$size = $rx.Match($line).value
$drive = $drive -replace ':'
$clusterSize.$drive = $size
}
else {"Drive $drive was not found"}
}
$clusterSize | format-table -auto -hide
}

Get-ClusterSize c, d

C 4096
D 4096

If the function is dot sourced you can access a drive's cluster size like:

$clusterSize.d
4096

--
Kiron

My System SpecsSystem Spec
07-14-2007   #8 (permalink)
Kiron


 

Re: Getting the 'cluster size' of your hard disk?

Adjusted with Matthias' solution for NTFS drives only:
Lighting fast.

function Get-ClusterSize ([char[]]$driveLetter = 'c')
{
$clusterSize = @{}
foreach ($drive in $driveLetter)
{
$drive = $($drive + ':').toUpper()
if (test-path $drive)
{
fsutil fsinfo ntfsinfo $drive > outPut
$line = (select-string 'Bytes Per Cluster' outPut).line
remove-item outPut
[regex]$rx = '\d+'
$size = $rx.Match($line).value
$drive = $drive -replace ':'
$clusterSize.$drive = $size
}
else {"Drive $drive was not found"}
}
$clusterSize | format-table -auto -hide
}

Get-ClusterSize c, d

C 4096
D 4096

If the function is dot sourced you can access a drive's cluster size like:

$clusterSize.d
4096

--
Kiron
My System SpecsSystem Spec
07-14-2007   #9 (permalink)
Matthias Tacke


 

Re: Getting the 'cluster size' of your hard disk?

Kiron wrote:
> Adjusted with Matthias' solution for NTFS drives only:
> Lighting fast.
>
> function Get-ClusterSize ([char[]]$driveLetter = 'c')
> {
> $clusterSize = @{}
> foreach ($drive in $driveLetter)
> {
> $drive = $($drive + ':').toUpper()
> if (test-path $drive)
> {
> fsutil fsinfo ntfsinfo $drive > outPut
> $line = (select-string 'Bytes Per Cluster' outPut).line
> remove-item outPut
> [regex]$rx = '\d+'
> $size = $rx.Match($line).value
> $drive = $drive -replace ':'
> $clusterSize.$drive = $size
> }
> else {"Drive $drive was not found"}
> }
> $clusterSize | format-table -auto -hide
> }
>
> Get-ClusterSize c, d
>
> C 4096
> D 4096
>
> If the function is dot sourced you can access a drive's cluster size like:
>
> $clusterSize.d
> 4096
>


Hi Kiron,
the output of fsutil is locale dependent. My German version has
'Bytes pro Cluster :' so:
$line = (select-string 'Byte.*Cluster' outPut).line
should be a bit more universal albeit not perfect.

--
Greetings
Matthias
My System SpecsSystem Spec
07-14-2007   #10 (permalink)
Kiron


 

Re: Getting the 'cluster size' of your hard disk?

Thanks for pointing that out, and for your solution. The good thing is that
the script is easy to adjust depending on the locale.

Danke


--
Kiron

My System SpecsSystem Spec
 

Getting the 'cluster size' of your hard disk? problems?



Thread Tools


Similar topics to: Getting the 'cluster size' of your hard disk?
Thread Forum
VPC 2007 - how to shrink the virtual hard disk size Virtual PC
RE: increase hard disk size Virtual PC
Hard Disk Size Discrepancy Virtual PC
Changing size of Virtual PC 2007 hard disk Virtual PC
Cluster size question Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50