Share via

Exclude disabled users

Arosh Wijepala 161 Reputation points
2021-10-13T13:31:33.173+00:00

I'm using the below code to get a list of email addresses of users in an AD group. I need to exclude the disabled users from that. What do I need to add to achieve that?

Get-ADGroupMember -Identity "EMEASenders" -Recursive | Get-ADUser -Property Mail | Select-Object Mail | Export-csv -path C:\temp\Email.csv -NoTypeInformation
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Rich Matheisen 48,116 Reputation points
    2021-10-13T14:22:21.307+00:00

    Try this:

    Get-ADGroupMember -Identity "EMEASenders" -Recursive | 
        Get-ADUser -Property Mail | 
            Where-Object {$_.Enabled} |
                Select-Object Mail | 
                    Export-csv -path C:\temp\Email.csv -NoTypeInformation
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.