Custom Inventory Rule - Profile Size

I'm wanting to get the profile size from every PC. 

The CIR below returns all the 'profiles' but shows 0.00 for the size

ShellCommandTextReturn(powershell -command "$fso = new-object -com Scripting.FileSystemObject; gci -Directory c:\users\| select @{l='Size'; e={$fso.GetFolder($_.FullName).Size}},FullName | sort Size -Descending | ft @{l='Size [MB]'; e={'{0:N2}    ' -f ($_.Size / 1MB)}},FullName")

this PS returns the info I want, but doesn't seem to work in the CIR.  Ive tried to use "ShellCommandTextReturn(powershell.exe "invoke-command –ScriptBlock {" in front of the PS and still no joy. 

$UserFolders = Get-ChildItem -Path 'C:\Users' -Force -Directory
ForEach ( $Folder in $UserFolders ) {
    $FolderSize = ( Get-Childitem -Path $Folder.FullName -Force -Recurse | Measure-Object -Property "Length" -Sum ).Sum /1GB
        FolderName    = $Folder.BaseName
        FolderPath    = $Folder.FullName
        Size          = $FolderSize

0 Comments   [ + ] Show comments

Answers (1)

Posted by: tshupp 3 days ago
3rd Degree Black Belt

Check out this blog from awhile back:

Windows Rule:

ShellCommandTextReturn(powershell -Command "& {Get-ChildItem C:\Users -recurse -force -ErrorAction "SilentlyContinue" | Measure-Object -property length -sum -maximum -minimum}")

Example output:

Count : 156707
Average : 
Sum : 100229316154
Maximum : 1033927956
Minimum : 0
Property : length


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