-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShow-UserProfileSize.PS1
36 lines (28 loc) · 1.2 KB
/
Show-UserProfileSize.PS1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Function Show-UserProfileSize {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]$UserName,
[Switch]$ShowTotalProfileSize
)
$RootFolders = Get-ChildItem -Path c:\users\$Username -Force | Where Mode -Like 'D*'
$RootFolderFiles = Get-ChildItem -Path c:\users\$Username -Force | Where Mode -notLike 'D*'
$Results = Foreach ($Folder in $RootFolders){
$CurrentFolderFiles = Get-ChildItem -Path $Folder.Fullname -Recurse -Force -ErrorAction SilentlyContinue|
Where Mode -NotLike 'D*'
$FolderSize = ($CurrentFolderFiles | Measure -Sum Length).Sum / 1mb
$Props = [Ordered]@{
'Folder Name' = $Folder.Name;
'Folder Size (MB)' = [math]::Round($FolderSize)
}
$obj = New-Object -TypeName psobject -Property $Props
$obj
}
#This displays the folders next to their total folder size
$Results
Write-Output ""
#This will find the total size
if ($ShowTotalProfileSize) {
$RawProfileSize = ($Results | Measure -Sum 'Folder Size (MB)').Sum * 1MB
Write-Output "The total size of the local profile for $UserName is $($RawprofileSize /1mb) MB."
}
}