This script will loop through all the folders in the “C:\Users” directory and check if they are a container (i.e. a folder). If they are, it will calculate the size of the folder (including all subfolders and files) using the Measure-
$users = Get-ChildItem -Path “C:\Users”
foreach ($user in $users) {
if ($user.PSIsContainer) {
$folderSize = (Get-ChildItem $user.FullName -Recurse | Measure-Object -Property Length -Sum).Sum
$folderLastModified = (Get-ChildItem $user.FullName -Recurse | Sort-Object LastWriteTime -Descending | Select-Object -First 1).LastWriteTime
Write-Host “User: $($user.Name) – Folder Size: $($folderSize/1MB) MB – Last Modified: $folderLastModified”
}
}