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-14-2007   #11 (permalink)
hecks@hotmail.co.uk


 

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

On Jul 14, 8:55 pm, "Kiron" <Ki...@HighPlainsDrifter.com> wrote:
> 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




Nice, thank you. The intermediary file and select-string can be
avoided with a small tweak, I think:

$fs = fsutil fsinfo ntfsinfo $drive
$reg = [regex]'(?<=Bytes.*Cluster.*)\d+'
$size = ($fs | %{$reg.matches($_)}).value

or:

$reg = '(?<=Bytes.*Cluster.*)\d+'
$fs = (fsutil fsinfo ntfsinfo $drive) | ?{$_ -match $reg}
$size = $matches[0]

That seems to work fine on my end, anyway.

-Hecks

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


 

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

Works here too, they both do, although the first one is slightly faster than
the second one.
Good performance enhancement, less lines and it's faster than the original.
Thanks for sharing the improvement, they're always welcome, corrections too.

--
Kiron

My System SpecsSystem Spec
07-14-2007   #13 (permalink)
hecks@hotmail.co.uk


 

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

On Jul 15, 4:57 am, "Kiron" <Ki...@HighPlainsDrifter.com> wrote:
> Works here too, they both do, although the first one is slightly faster than
> the second one.
> Good performance enhancement, less lines and it's faster than the original.
> Thanks for sharing the improvement, they're always welcome, corrections too.
>
> --
> Kiron


Glad to help. I've been regexing a lot recently, so it's always
interesting to see the different ways it can be optimized in PS.

This is perhaps a clearer way of writing it, though it doesn't seem to
be any faster:

# outside the foreach loop
$reg = [regex]'(?<=Bytes.*Cluster.*)\d+'

# inside the foreach loop
$fs = fsutil fsinfo ntfsinfo $drive
$size = $reg.match($fs).value

There are just so many ways of doing the same thing in PS, it's
insane ...

-Hecks

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


 

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

PowerShell is very versatile.
Here's another way, shorter and a bit faster. This time it gets the
fifteenth line of fsutil's output --considering locale, thanks Matthias--
and removes any nondigit from it to get the cluster's size. Also no
unnecessary repetitive declaration inside the foreach loop --thanks Hecks.
It also relies on the uniformity of fsutil's output in different
languages --of which I know nothing about.


function Get-ClusterSize ([char[]]$driveLetter = 'c')
{
$clusterSize = @{}
foreach ($drive in $driveLetter)
{
$drive = $($drive + ':').toUpper()
if (test-path $drive)
{
$size = (fsutil fsinfo ntfsinfo $drive)[14] -replace '\D'
$drive = $drive[0]
$clusterSize.$drive = $size
}
else {"Drive $drive was not found"}
}
$clusterSize | format-table -auto -hide
}


--
Kiron

My System SpecsSystem Spec
07-16-2007   #15 (permalink)
Jacques Barathon [MS]


 

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

"Kiron" <Kiron@HighPlainsDrifter.com> wrote in message news:8D925A4E-D250-467D-B6EA-E0D2D8981597@microsoft.com...
> PowerShell is very versatile.
> Here's another way, shorter and a bit faster. This time it gets the
> fifteenth line of fsutil's output --considering locale, thanks Matthias--
> and removes any nondigit from it to get the cluster's size. Also no
> unnecessary repetitive declaration inside the foreach loop --thanks Hecks.
> It also relies on the uniformity of fsutil's output in different
> languages --of which I know nothing about.

....

Here's a sligthly shorter version which has the advantage in my eyes of providing raw data thus allowing for further handling down the pipeline (e.g. formatting or measuring):

--- get-clustersize.ps1 ---
param ([char[]]$drive = "c")

$drive | foreach {
if (test-path "$($_):") {
$cs = new-object PSObject
$cs | add-member NoteProperty Drive $_
$cs | add-member NoteProperty Size (fsutil fsinfo ntfsinfo "$($_):")[14].split()[-1]
$cs
}
}
--- end of file ---

Jacques

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