Created
June 3, 2021 15:48
-
-
Save sandeep-sr/b8e43f67a370b29886f61311424c54e7 to your computer and use it in GitHub Desktop.
powershell - find disabled ad user accounts
This file contains hidden or 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
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