![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||