Powershell script to find the users folder size and last modified

PowerShell script to find user profile that not used for long time
January 23, 2023
PowerShell script to find the users folder size and last modified more than 90 days and csv export
January 23, 2023

Powershell script to find the users folder size and last modified

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”
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *