How to get folder size by excluding a sub folder ?

namerg
namerg used Ask the Experts™
on
I would like to have the folder size of the following path "C:\ArchiveDocs\DocImageExports\Servicing" by excluding "C:\ArchiveDocs\DocImageExports\Servicing\Old"

This code gives me everything including "Old". I need to exclude the "Old" folder.
"{0:N2} GB" -f ((Get-ChildItem "C:\ArchiveDocs\DocImageExports\Servicing\" -Recurse |  Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB)

Open in new window


Thanks for your help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
How about the brute force approach?
$AllSize = (Get-ChildItem "C:\ArchiveDocs\DocImageExports\Servicing\" -Force -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum
$OldSize = (Get-ChildItem "C:\ArchiveDocs\DocImageExports\Servicing\Old" -Force -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum
"{0:N2} GB" -f (($AllSize - $OldSize) / 1GB)

Open in new window

namergSystems Administrator

Author

Commented:
Jajaja, that did the trick.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial