I have a folders called "Approved for Destruction after 09-15-13", and I want to find out how much is stored in each of these folders via a KACE Custom Inventory Rule. The trick is that these folders are located in each department's folder and those can be named a lot of different things. i.e. "\Dept\Marketing\Approved for Destruction after 09-15-13" or "\Dept\Accounting\Approved for Destruction after 09-15-13" etc. I know that SysInternals has DU.exe for folder size checks, but that requires a definitive folder location and won't take a wildcard in the "Marketing" or "Accounting" location... Thoughts?

0 Comments   [ + ] Show Comments


Please log in to comment

Community Chosen Answer


Would something like this work using recursive lookup?

Function FolderSize


$startFolder = "C:\Temp"


$colItems = (Get-ChildItem $startFolder | Measure-Object -property length -sum)

"$startFolder -- " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB"


$colItems = (Get-ChildItem $startFolder -recurse | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)

foreach ($i in $colItems)


        $subFolderItems = (Get-ChildItem $i.FullName | Measure-Object -property length -sum)

        $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"


    FolderSize |Out-file C:\temp\folder.txt



Then have the inventory rule read C:\temp\folder.txt.

ShellCommandTextReturn(cmd.exe /c type C:\temp\folder.txt)
Answered 09/04/2013 by: dugullett
Red Belt

Please log in to comment



This seems to work to view subfolders (tested in version 5.5):

ShellCommandTextReturn(dir c:\dept /s)

Answered 09/04/2013 by: jknox
Red Belt

  • better wrap it in cmd /c as some ShellCommandTextReturn CIR don't run in 5.5 if not wrapped.
Please log in to comment

I got this working in a batch file.  We're not on 5.5, so I didn't bother testing in a custom inventory rule.

This will search the drive for any folder named "approved for destruction after 09-15-13" and return the folder size and folder path.  You can install gnu coreutils (or just cut) and pipe to cut -f1 to only return the numerical value for the folder size.

for /f "tokens=*" %%a in ('dir /s /ad /b .\"Approved for Destruction after 09-15-13?".') do (du "%%a")


Answered 09/06/2013 by: adambrock
White Belt

Please log in to comment
Answer this question or Comment on this question for clarity