Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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 > Misc Newsgroups > PowerShell

Vista - Size of network folder

Closed Thread
 
Old 07-08-2008   #1 (permalink)
Tommy Holm Jakobsen


 
 

Size of network folder

Hi,

How can I compute the size of a folder located on the network?

The address is something like: \\server\customer$\tsprofile\user.name

I've found a script, but it doesn't work when I run it on a network
folder:

function Get-DirectorySize
{
param ($path = {(Get-Location).Path});
if (! $GLOBAL:_FileSystemObject)
{
$GLOBAL:_FileSystemObject = New-Object -comobject
"Scripting.FileSystemObject";
}
($GLOBAL:_FileSystemObject.GetFolder($path)).Size;
}

Thanks in advance

Tommy

My System SpecsSystem Spec
Old 07-08-2008   #2 (permalink)
Kirk Munro [MVP]


 
 

Re: Size of network folder

Get-ChildItem \\someComputer\someShare\somePath -Recurse |
ForEach-Object -Begin {$totalSize = 0} -Process {$totalSize +=
$_.Length} -End {"Total size: $totalSize"}

or if you want to save some typing:

gci \\someComputer\someShare\somePath -r | % -b {$t=0} -p
{$t+=$_.Length} -en {$t}

--
Kirk Munro [MVP]
Poshoholic
http://poshoholic.com

"Tommy Holm Jakobsen" <tommy@xxxxxx> a écrit dans le message de
groupe de discussion : ati774hg5gr9u2ntd0s0o7cl6f4j24sa9m@xxxxxx...
Quote:

> Hi,
>
> How can I compute the size of a folder located on the network?
>
> The address is something like: \\server\customer$\tsprofile\user.name
>
> I've found a script, but it doesn't work when I run it on a network
> folder:
>
> function Get-DirectorySize
> {
> param ($path = {(Get-Location).Path});
> if (! $GLOBAL:_FileSystemObject)
> {
> $GLOBAL:_FileSystemObject = New-Object -comobject
> "Scripting.FileSystemObject";
> }
> ($GLOBAL:_FileSystemObject.GetFolder($path)).Size;
> }
>
> Thanks in advance
>
> Tommy
My System SpecsSystem Spec
Old 07-08-2008   #3 (permalink)
Kirk Munro [MVP]


 
 

Re: Size of network folder

I forgot one thing. Use -Force with Get-ChildItem so that hidden files are
included in your total. Otherwise hidden files will be excluded. So your
one-liner should be this:

Get-ChildItem \\someComputer\someShare\somePath -Recurse -Force |
ForEach-Object -Begin {$totalSize = 0} -Process {$totalSize +=
$_.Length} -End {"Total size: $totalSize"}

or the short version:

gci \\someComputer\someShare\somePath -r -fo | % -b {$t=0} -p
{$t+=$_.Length} -en {$t}

--
Kirk Munro [MVP]
Poshoholic
http://poshoholic.com

"Kirk Munro [MVP]" <see.my.about.page.on@xxxxxx> a écrit
dans le message de groupe de discussion :
5EB99CC9-9903-40C2-B6D6-1EC752F8B833@xxxxxx...
Quote:

> Get-ChildItem \\someComputer\someShare\somePath -Recurse |
> ForEach-Object -Begin {$totalSize = 0} -Process {$totalSize +=
> $_.Length} -End {"Total size: $totalSize"}
>
> or if you want to save some typing:
>
> gci \\someComputer\someShare\somePath -r | % -b {$t=0} -p
> {$t+=$_.Length} -en {$t}
>
> --
> Kirk Munro [MVP]
> Poshoholic
> http://poshoholic.com
>
> "Tommy Holm Jakobsen" <tommy@xxxxxx> a écrit dans le message de
> groupe de discussion : ati774hg5gr9u2ntd0s0o7cl6f4j24sa9m@xxxxxx...
Quote:

>> Hi,
>>
>> How can I compute the size of a folder located on the network?
>>
>> The address is something like: \\server\customer$\tsprofile\user.name
>>
>> I've found a script, but it doesn't work when I run it on a network
>> folder:
>>
>> function Get-DirectorySize
>> {
>> param ($path = {(Get-Location).Path});
>> if (! $GLOBAL:_FileSystemObject)
>> {
>> $GLOBAL:_FileSystemObject = New-Object -comobject
>> "Scripting.FileSystemObject";
>> }
>> ($GLOBAL:_FileSystemObject.GetFolder($path)).Size;
>> }
>>
>> Thanks in advance
>>
>> Tommy
>
My System SpecsSystem Spec
Old 07-09-2008   #4 (permalink)
RichS [MVP]


 
 

Re: Size of network folder

You could also use Measure-Object to sum the lengths of the files for you

Get-ChildItem \\someComputer\someShare\somePath -Recurse -Force |
measure-object -property length -sum

It will also give you a count of the number of files
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Kirk Munro [MVP]" wrote:
Quote:

> I forgot one thing. Use -Force with Get-ChildItem so that hidden files are
> included in your total. Otherwise hidden files will be excluded. So your
> one-liner should be this:
>
> Get-ChildItem \\someComputer\someShare\somePath -Recurse -Force |
> ForEach-Object -Begin {$totalSize = 0} -Process {$totalSize +=
> $_.Length} -End {"Total size: $totalSize"}
>
> or the short version:
>
> gci \\someComputer\someShare\somePath -r -fo | % -b {$t=0} -p
> {$t+=$_.Length} -en {$t}
>
> --
> Kirk Munro [MVP]
> Poshoholic
> http://poshoholic.com
>
> "Kirk Munro [MVP]" <see.my.about.page.on@xxxxxx> a crit
> dans le message de groupe de discussion :
> 5EB99CC9-9903-40C2-B6D6-1EC752F8B833@xxxxxx...
Quote:

> > Get-ChildItem \\someComputer\someShare\somePath -Recurse |
> > ForEach-Object -Begin {$totalSize = 0} -Process {$totalSize +=
> > $_.Length} -End {"Total size: $totalSize"}
> >
> > or if you want to save some typing:
> >
> > gci \\someComputer\someShare\somePath -r | % -b {$t=0} -p
> > {$t+=$_.Length} -en {$t}
> >
> > --
> > Kirk Munro [MVP]
> > Poshoholic
> > http://poshoholic.com
> >
> > "Tommy Holm Jakobsen" <tommy@xxxxxx> a crit dans le message de
> > groupe de discussion : ati774hg5gr9u2ntd0s0o7cl6f4j24sa9m@xxxxxx...
Quote:

> >> Hi,
> >>
> >> How can I compute the size of a folder located on the network?
> >>
> >> The address is something like: \\server\customer$\tsprofile\user.name
> >>
> >> I've found a script, but it doesn't work when I run it on a network
> >> folder:
> >>
> >> function Get-DirectorySize
> >> {
> >> param ($path = {(Get-Location).Path});
> >> if (! $GLOBAL:_FileSystemObject)
> >> {
> >> $GLOBAL:_FileSystemObject = New-Object -comobject
> >> "Scripting.FileSystemObject";
> >> }
> >> ($GLOBAL:_FileSystemObject.GetFolder($path)).Size;
> >> }
> >>
> >> Thanks in advance
> >>
> >> Tommy
> >
My System SpecsSystem Spec
Old 10-01-2008   #5 (permalink)
D Lee


 
 

Re: Size of network folder

If that didn't work, try this:

$startfolder = Read-Host "Enter server name and path (i.e.
\\servername\share)"

$colItems = (Get-childitem $startfolder | Where-object {$_.PSIsContainer -eq
$True} | sort-object)
foreach ($i in $colitems)

{
$patho = $i.fullname
$objFSO = New-Object -com Scripting.FileSystemObject
$total = "{0:N2}" -f (($objFSO.GetFolder($patho).Size) / 1MB) + " MB"
$output = $patho + ' ' + $total
write-output $output
}

The code that generates the output is a little clunky, but it works for me.

"RichS [MVP]" wrote:
Quote:

> You could also use Measure-Object to sum the lengths of the files for you
>
> Get-ChildItem \\someComputer\someShare\somePath -Recurse -Force |
> measure-object -property length -sum
>
> It will also give you a count of the number of files
> --
> Richard Siddaway
> All scripts are supplied "as is" and with no warranty
> PowerShell MVP
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "Kirk Munro [MVP]" wrote:
>
Quote:

> > I forgot one thing. Use -Force with Get-ChildItem so that hidden files are
> > included in your total. Otherwise hidden files will be excluded. So your
> > one-liner should be this:
> >
> > Get-ChildItem \\someComputer\someShare\somePath -Recurse -Force |
> > ForEach-Object -Begin {$totalSize = 0} -Process {$totalSize +=
> > $_.Length} -End {"Total size: $totalSize"}
> >
> > or the short version:
> >
> > gci \\someComputer\someShare\somePath -r -fo | % -b {$t=0} -p
> > {$t+=$_.Length} -en {$t}
> >
> > --
> > Kirk Munro [MVP]
> > Poshoholic
> > http://poshoholic.com
> >
> > "Kirk Munro [MVP]" <see.my.about.page.on@xxxxxx> a crit
> > dans le message de groupe de discussion :
> > 5EB99CC9-9903-40C2-B6D6-1EC752F8B833@xxxxxx...
Quote:

> > > Get-ChildItem \\someComputer\someShare\somePath -Recurse |
> > > ForEach-Object -Begin {$totalSize = 0} -Process {$totalSize +=
> > > $_.Length} -End {"Total size: $totalSize"}
> > >
> > > or if you want to save some typing:
> > >
> > > gci \\someComputer\someShare\somePath -r | % -b {$t=0} -p
> > > {$t+=$_.Length} -en {$t}
> > >
> > > --
> > > Kirk Munro [MVP]
> > > Poshoholic
> > > http://poshoholic.com
> > >
> > > "Tommy Holm Jakobsen" <tommy@xxxxxx> a crit dans le message de
> > > groupe de discussion : ati774hg5gr9u2ntd0s0o7cl6f4j24sa9m@xxxxxx...
> > >> Hi,
> > >>
> > >> How can I compute the size of a folder located on the network?
> > >>
> > >> The address is something like: \\server\customer$\tsprofile\user.name
> > >>
> > >> I've found a script, but it doesn't work when I run it on a network
> > >> folder:
> > >>
> > >> function Get-DirectorySize
> > >> {
> > >> param ($path = {(Get-Location).Path});
> > >> if (! $GLOBAL:_FileSystemObject)
> > >> {
> > >> $GLOBAL:_FileSystemObject = New-Object -comobject
> > >> "Scripting.FileSystemObject";
> > >> }
> > >> ($GLOBAL:_FileSystemObject.GetFolder($path)).Size;
> > >> }
> > >>
> > >> Thanks in advance
> > >>
> > >> Tommy
> > >
My System SpecsSystem Spec
Closed Thread

Thread Tools


Similar Threads
Thread Forum
Folder Size Tutorials
Folder Size in Size Column Vista file management
Folder Size Vista General
Folder size Vista General
Folder size? Vista General


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