Created
January 9, 2018 14:47
-
-
Save amnich/7ca43f8859184422c81d07bc7dfe777d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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