Skip to content

Instantly share code, notes, and snippets.

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 sandeep-sr/b8e43f67a370b29886f61311424c54e7 to your computer and use it in GitHub Desktop.
Save sandeep-sr/b8e43f67a370b29886f61311424c54e7 to your computer and use it in GitHub Desktop.
powershell - find disabled ad user accounts
Import-Module Active*
$userdata=get-content c:\temp\useraccounts.txt
foreach($user in $userdata)
{
try
{
$Disabled=(Get-ADUser -Identity $user).Enabled
if($Disabled -match "False")
{
Write-Output "$user is disabled"
Write-Output "$user"|Out-File c:\temp\Disabled.txt -Append
}
elseif($Disabled -match "True")
{
Write-Output "$user is exists"
Write-Output "$user"|Out-File c:\temp\enabled.txt -Append
}
else
{
Write-Output "either a contact/account not exists"
Write-Output "$user"|Out-File c:\temp\conno.txt -Append
}
}
catch
{
Write-Output "$user is contact"
Write-Output "$user"|Out-File c:\temp\contact.txt -Append
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment