Script to check if Active Directory User Account is Active or Disabled throught Powershell

Below powershell helps to get if a give account is active or disabled, We can loop it for the given list of users

$K = “Krishna.k”
$adobjroot = [adsi]”
$objdisabsearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
$objdisabsearcher.filter = “(&(objectCategory=user)(objectClass=user)(sAMAccountName= $K)(userAccountControl:1.2.840.113556.1.4.803:=2))”
$resultdisabaccn = $objdisabsearcher.findone()

if($resultdisabaccn)
{
 Write-Output “ACcount is Disabled”
}
 Else
{
 Write-Output “ACcount is Active”
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s