Skip to content

Instantly share code, notes, and snippets.

@NotoriousPyro
Last active August 18, 2021 09:54
Show Gist options
  • Save NotoriousPyro/dbfa1b4c5d7ef302e7282d8a67c900ac to your computer and use it in GitHub Desktop.
Save NotoriousPyro/dbfa1b4c5d7ef302e7282d8a67c900ac 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