Skip to content

Instantly share code, notes, and snippets.

@mjsqu
Created November 27, 2018 01:02
Show Gist options
  • Save mjsqu/1df68e5224598b5ada11cccddfd9347a to your computer and use it in GitHub Desktop.
Save mjsqu/1df68e5224598b5ada11cccddfd9347a to your computer and use it in GitHub Desktop.
# Grab files from your user profile
# -Force - gets hidden files
# -ErrorAction - suppresses errors associated with permissions
# PSISContainer is only true for folders - so only pick where false
$files = Get-ChildItem $env:USERPROFILE -Recurse -Force -ErrorAction SilentlyContinue | Where-Object {$_.PSISContainer -eq $false}
Write-Host "Total User Profile takes up: {0} KB" -f [int]$($($files | Measure-Object -sum Length).Sum/1024)
# Display an Out-GridView showing the top $n files
$n = 20
$deletelist = $files | Sort-Object Length -Descending | Select-Object FullName, Length -First $n | Out-GridView -PassThru
# Delete the files selected
ForEach ($file in $deletelist) {
Remove-Item $file.FullName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment