Link to home
Start Free TrialLog in
Avatar of RobZimmerman
RobZimmermanFlag for United States of America

asked on

PowerShell script to display all email addresses where the department = X

Hi everyone,

Very new to powershell and at this point I need to punt and just ask for the command here. What I have so far is:

Get-ADUser -Filter * -Properties EmailAddress, Department | select EmailAddress, Department

What I ultimately need to do is filter it to where Department = Logistics and so on and so forth.

I really appreciate your help,
Mike
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

get-aduser -Filter {mail -like "*"} -Properties UserPrincipalName,mail,Department | select UserPrincipalName,mail,Department | where Department -like "Logistics*" | ft -a

This should give you what you are looking for.

Dan
Avatar of RobZimmerman

ASKER

This is awesome, thank you! I should have added that I need to add the ability to export this to a csv, will a "Export-Csv c:\ps_test\test.txt" work?
ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial