Skip to content

Instantly share code, notes, and snippets.

@BjoernSchilberg
Forked from NotoriousPyro/ProfilesPS.bat
Created August 18, 2021 09:54
Show Gist options
  • Save BjoernSchilberg/e4c466579550c502c8ca4be7327647f3 to your computer and use it in GitHub Desktop.
Save BjoernSchilberg/e4c466579550c502c8ca4be7327647f3 to your computer and use it in GitHub Desktop.
This is a PowerShell script I developed to delete all local profiles off the target PC that aren't: loaded, special (system profiles), have never been logged into, and that have not been used for more than 1 day. The last parameter is configurable via -lt (Get-Date).AddDays(-1)). It will safely delete profiles to avoid system issues such as loca…
@ECHO OFF
echo Powershell profile deleter
set /p PCNAME="PC:"
Powershell -Mta -NoProfile -Command "& {Get-WmiObject Win32_UserProfile -Computer %PCNAME% | Where {(!$_.Special) -and (!$_.Loaded) -and ($_.LastUseTime -ne $null) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-1))} | Remove-WmiObject -Verbose}"
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment