Solved

check if ad account is disabled

Posted on 2016-08-16
4
91 Views
Last Modified: 2016-08-16
How can I check to see if and AD account is disabled?  I assume the code below does not work but this is what im thinking

if(samaccountname.disabled = true){

do this

}
0
Comment
Question by:Roccat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 30

Expert Comment

by:Rich Weissler
ID: 41757791
Once you get the User object (via get-aduser), you can check the 'enabled' property...
(I did a "get-aduser <username> -properties enabled", then could check the 'enabled' property... if false, then the account is disabled.)
0
 

Author Comment

by:Roccat
ID: 41757797
Thank you. What is the syntax to check if the enabled property is true?
0
 
LVL 30

Accepted Solution

by:
Rich Weissler earned 500 total points
ID: 41757807
Sorry...
$a = get-aduser <username> -properties enabled
if (! $a.enabled) {
   do this if disabled
}
else {
    do this if enable
}

Open in new window

0
 

Author Closing Comment

by:Roccat
ID: 41757830
Thank you!!
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question