Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2019 17:28
What would you like to do?
Get-UserProfileSize retrieves the profile size information of each locally stored profile. The command retrieves the
size of the profile Document and Desktop folder and the full profile size but excluding the AppData\local folder
Get-UserProfileSize -OutPutLocation C:\Temp -Verbose
This command retrieves the profile size of all users and stores the results into the defined folder
v1.0, 28.08.2019, alex verboon, initial version
v1.1, 04.09.2019, alex verboon, adjustments to meet ConfigMgr script output requirements
Credits: The original profile collection script was taken from Mick Pletchers blog
# Results output location
Set-Culture "en-US"
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "system.globalization.CultureInfo" "en-US"
#Full path and filename of the file to write the output to
$File = "$OutPutLocation\ProfileSizeReport.csv"
Write-verbose "OutPutFile: $file"
#Exclude these accounts from reporting
$Exclusions = ("Administrator", "Default", "Public","ladmin")
Write-Verbose "Excluded Profiles: $Exclusions"
Process {
Write-Verbose "Retrieving Profiles"
$Profiles = Get-ChildItem -Path $env:SystemDrive"\Users" | Where-Object { $_ -notin $Exclusions } | Sort-Object LastWriteTime -Descending
$AllProfiles = @()
foreach ($Profile in $Profiles) {
Write-Verbose "Processing Profile $Profile"
$object = New-Object -TypeName System.Management.Automation.PSObject
#Get the size of the Documents and Desktop combined and round with no decimal places
Write-Verbose "Retrieving User Profile Documents and Desktop size"
$object | Add-Member -MemberType NoteProperty -Name ComputerName -Value $env:COMPUTERNAME.ToUpper()
$object | Add-Member -MemberType NoteProperty -Name Profile -Value $Profile.Name
$DocFolderSizes = ((Get-ChildItem ($Profile.FullName + '\Documents'), ($Profile.FullName + '\Desktop') -Recurse) | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum
$DocFolderSizes = 0
$Object | Add-Member -MemberType NoteProperty -Name DocSize -Value $DocFolderSizes
$Object | Add-Member -MemberType NoteProperty -Name DocSizeMB -Value ($DocFolderSizes/1mb)
Write-Verbose "Retrieving Full User Profile size -excluding \AppData\Local"
$FoldersizesFull = ((Get-ChildItem ($Profile.FullName) -Recurse -Exclude ($Profile.FullName + '\AppData\Local')) | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum
$FoldersizesFull = 0
$object | Add-Member -MemberType NoteProperty -Name FullSize -Value $FoldersizesFull
$object | Add-Member -MemberType NoteProperty -Name FullSizeMB -Value ($FoldersizesFull/1mb)
$AllProfiles += $object
#Create the formatted entry to write to the file
[string]$Output = $null
foreach ($Entry in $AllProfiles) {
[string]$Output += $Entry.ComputerName + ',' + $Entry.Profile + ',' + $Entry.DocSize + ',' + $Entry.DocSizeMB + ',' + $Entry.FullSize + ',' + $Entry.FullSizeMB + [char]13
#Remove the last line break
$Output = $Output.Substring(0,$Output.Length-1)
#Write the output to the specified CSV file. If the file is opened by another machine, continue trying to open until successful
Do {
Try {
$Output | Out-File -FilePath $File -Encoding UTF8 -Append -Force
$Success = $true
} Catch {
$Success = $false
} while ($Success = $false)
Return $AllProfiles | Select-Object Computername, Profile, DocSize,DocSizeMB,FullSize, FullSizeMB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment