Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sandeep-sr/b8e43f67a370b29886f61311424c54e7 to your computer and use it in GitHub Desktop.

Select an option

Save sandeep-sr/b8e43f67a370b29886f61311424c54e7 to your computer and use it in GitHub Desktop.

Revisions

  1. sandeep-sr created this gist Jun 3, 2021.
    33 changes: 33 additions & 0 deletions powershell_find_ad_disabled_accounts.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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
    }
    }