Get Folder Sizes from 2 locations and add the total

I run a month end billing process requiring me to look at folder A on drive d: and folder A on drive e: - I have to do a properties on each to get each size and then add them together for a total data size for customer A. Then I repeat this for customer B, C D ect.

Is there a way to do this using PS that would make the process easier… ??

Yes, you will need to map the drives with New-PSDrive and then you will be able to gather data on them with PowerShell. With a little loop logic and some arithmetic you should be able to do this reliably on as many different systems as you need to.


$clients = Get-ChildItem "E:\" # | select -first 1 | fl *
$outlist = @()
foreach($cl in $clients) {
#$cl = $clients[3]
$fold = $cl.FullName
Write-Host -ForegroundColor Green $fold
$count = 0
$size = 0
# Count E: drive files for client
foreach ($item in (Get-ChildItem $fold -recurse -File -Force | ForEach-Object {$_.FullName})) {
$count = $count + 1
$size += (Get-Item $item -Force).length
# Count D: drive files for client (if exists)
$dpath = "D:\" + $cl.Name
if(Test-Path $dpath){
Write-Host -ForegroundColor Green $dpath
foreach ($item in (Get-ChildItem $dpath -recurse -File -Force | ForEach-Object {$_.FullName})) {
$count = $count + 1
$size += (Get-Item $item -Force).length
$out = @{}
$out.FolderName = $cl.Name
$out.FileCount = $count
$out.FolderSizeInGB = [Math]::Round($size / 1GB,2)
#"{0:N2} MB" -f ($size / 1MB)
Write-Host -ForegroundColor Green "$count files"
$outlist += New-Object PSObject -Property $out
Write-Host ""
$outlist | select FolderName, FolderSizeInGB, FileCount | ft -auto

$filename = "GF-Sizes_" + (get-date -Format yyyyMMdd-hhmmss) + ".csv"
$outlist | sort FolderName | select FolderName, FolderSizeInGB, FileCount |
Export-Csv -NoTypeInformation "C:\temp\output\$filename"


I am new to the forum but not new to powershell. I see so many admins try and ‘out-think’ what powershell needs to do. What Bruce Payette envisioned when he led the team at MS and developed PS, he envisioned a modular, expandable scripting environment.

When getting info about folder sizes, one does not need 36 lines of code. This is a one-liner. The only trick is understanding the extensibility of powershell. All you have to do is go to the powershell gallery and install PSScripttools by Jeff Hicks. Simple. You then will have an easy way to make this a one-liner.

Here is an example of how easy getting folder size info is. Run the following on your my documents folder AFTER installing PSScriptTools by Jeff Hicks:

get-childitem . -Directory | Get-FolderSizeInfo | ft -View mb

PowerShell is supposed to make our lives easier- not a throwback to complex VB scripting…