Skip to content

Instantly share code, notes, and snippets.

@amnich
Created January 9, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amnich/7ca43f8859184422c81d07bc7dfe777d to your computer and use it in GitHub Desktop.
Save amnich/7ca43f8859184422c81d07bc7dfe777d to your computer and use it in GitHub Desktop.
$profiles = Get-WmiObject -Class Win32_UserProfile
foreach ($prof in $profiles){
$sid = $prof.sid
$ADUser = Get-ADUser -Filter {SID -eq $sid}
if ($ADUser.enabled -eq $false){
#delete profile
"Delete $($ADUser.name)"
$prof.delete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment