Solved

Get list of users who are enabled in a specific AD group using Powershell

Posted on 2016-09-12
12
51 Views
1 Endorsement
Last Modified: 2016-09-12
I have been trying to get this Powershell script to work but I am having unexplained results.

As listed in the title I am trying to user Powershell to query an AD OU for users who are enabled.

Get-ADUser -SearchBase "OU=Example,DC=company,DC=net" -Filter {Enabled -eq "true"}

When I run this it consistently lists all users in the group. However I know for sure there are some enabled and some disabled users in the group.

If I switch the parameter to "false" it lists no users.

All users are in the same AD group, so if it helps I can specify that as well.

Any advice on what i need to do to list ONLY enabled users?

Thank in advance!
1
Comment
Question by:cmoerbe
  • 6
  • 5
12 Comments
 
LVL 54

Expert Comment

by:McKnife
ID: 41794196
Works here. Please double check.
Also try
Get-ADUser -SearchBase "OU=Example,DC=company,DC=net" -Filter {Enabled -eq "false"}

Open in new window

to see if the disabled ones are listed as expected.
0
 

Author Comment

by:cmoerbe
ID: 41794211
It tried Enabled -eq false and get zero records.

That's strange that it works as expected for you.

I am going to try it in a different AD environment and see if maybe that changes the results.

I dont really know how the cmd-let is gathering the enabled attribute, as i dont see a disabled/enabled property when using the -Filter *

Will report back soon.
0
 
LVL 54

Expert Comment

by:McKnife
ID: 41794217
Create a test account there and disable it and retry.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:cmoerbe
ID: 41794227
I created 6 test accounts. I then manually logged on / off of a domain computer with each account to fully establish activity with the account.

I then disabled 3 of 6 accounts in AD.

I then tried to log onto a domain computer with one of the disabled accounts to verify the setting took.

Will report back once I try in a different AD environment.
0
 
LVL 16

Expert Comment

by:FOX
ID: 41794231
Try this syntax not using the brackets

Get-ADUser -SearchBase "OU=Example,DC=company,DC=net" -Filter "Enabled -eq 'false'"
0
 

Author Comment

by:cmoerbe
ID: 41794246
I tried without the brackets and get similar responses.

'false' produces no accounts

'true' produces 6 accounts
0
 
LVL 54

Accepted Solution

by:
McKnife earned 500 total points
ID: 41794251
Tell me, what is the result of
net user oneusernamethatshouldbedisabled /domain |findstr active

Open in new window

?
0
 

Author Comment

by:cmoerbe
ID: 41794302
That helped me find the problem.

Im getting error code 5 - access denied (running PS as domain admin)

I closed PS and ran as administrator.....

Now all of the Powershell commands are working and producing the expected results.

Thanks for helping me figure that part out!!!
0
 

Author Closing Comment

by:cmoerbe
ID: 41794303
It was a permission issue with Powershell.

Thanks a TON for helping me to figure that out in a round about way.
0
 
LVL 54

Expert Comment

by:McKnife
ID: 41794421
Say, did you modify the OU security settings? normally, any user may read these attributes.
0
 

Author Comment

by:cmoerbe
ID: 41794467
I actually created a new OU / Group / User scenario during this process.

After your question I went and checked the OU permissions with ADSI edit.

It shows domain admins have full rights to the new OU I created.

When I was running Powershell as domain admin it was not generating any permission errors. Just returning either all users or no users.

Then after trying net user command in it immediately threw a permission error. That immediately made me think about Powershell not liking my domain admin approach. Run as administrator though had no problems.

Odd?
0
 
LVL 54

Expert Comment

by:McKnife
ID: 41794568
Please quote the complete permission list, there should be read permissions for the group authenticated users and various other entries, not just domain administrators.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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