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
[PSCustomObject]@{
FolderName = $Folder.BaseName
FolderPath = $Folder.FullName
Size = $FolderSize
}
}
Answers (1)
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
https://www.itninja.com/blog/view/calculating-user-folder-sizes
Comments:
-
This doesn't give me what I am looking for
I'm able to get this when I run the powershell code
employee C:\Users\employee 20
The link in the response gives a 'Custom Inventory Field' of
Count : 156707
Average :
Sum : 100229316154
Maximum : 1033927956
Minimum : 0
Property : length
I just want to know each 'user' and the size of the profile
I'm not sure why it is difficult to get this information from KACE - Leland 1 year ago