/build/static/layout/Breadcrumb_cap_w.png

Return Directory Size as Custom Inventory Rule in KACE

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

Answers (3)

Posted by: dugullett 11 years ago
Red Belt
3

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)
Posted by: jknox 11 years ago
Red Belt
2

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

ShellCommandTextReturn(dir c:\dept /s)


Comments:
  • better wrap it in cmd /c as some ShellCommandTextReturn CIR don't run in 5.5 if not wrapped. - Nico_K 11 years ago
Posted by: adambrock 11 years ago
White Belt
0

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")

 

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ