Powershell snippet 03: Report Disk usage of user profiles
This script will first retrieve a list of all user profiles on the system using the Get-WmiObject
cmdlet and the Win32_UserProfile
class. It will then calculate the total size of all profiles by summing the size of each profile. Finally, it will iterate through each profile and display the name and size of each profile, followed by the total size of all profiles.
Please note that this script will only work on Windows systems. If you need to run it on a different operating system, you will need to use a different method to retrieve a list of user profiles and their sizes.
Get a list of all user profiles on the system
$profiles = Get-WmiObject -Class Win32_UserProfile | Select-Object LocalPath, @{Name=’SizeMB’;Expression={($_.Size / 1MB)} }
Calculate the total size of all profiles
$totalSize = ($profiles | Measure-Object -Property SizeMB -Sum).Sum
Iterate through each profile and display the size
foreach ($profile in $profiles) { $profileName = $profile.LocalPath -replace ‘.*\\’,’’ $profileSizeMB = $profile.SizeMB Write-Output “$profileName: $profileSizeMB MB” }
Display the total size of all profiles
Write-Output “Total size of all profiles: $totalSize MB”