Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 44169
  • Last Modified:

Powershell: List AD group members but filter users who are disabled

Hi Experts,

I use the following line in Powershell to list AD Group members:

Get-ADGroupMember -identity "Group" | select name,samaccountname

How can I filter out the accounts that are disabled?

Thanks,

A.
0
Angeal
Asked:
Angeal
1 Solution
 
Mike KlineCommented:
Give this a try

Get-ADGroupMember -identity "Group" | get-aduser | Where {$_.Enabled -eq $true} | format-table name, samaccountname -autosize

Thanks

Mike
4
 
comfortjeaniusCommented:
You can try this

Get-ADGroupMember -Identity "GroupName" -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled }

Open in new window


To export it to a file

Get-ADGroupMember -Identity "GroupDN" -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled } | Export-Csv C:\ADResuts.csv

Open in new window

1
 
AngealAuthor Commented:
Exactly what I was looking for. Thanks Mike!
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
Mike KlineCommented:
Glad to help out!
0
 
dlo32Commented:
Nice script!  What would I need to add in order to include whether the members of the group have a smtp address?
0
 
dlo32Commented:
And to add to that,  what if I wanted to see all the members of nested groups beneath a particular group?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now