Export staff with different email domains from one Distribution List RRS feed

  • Question

  • Hi

    I've been stuck on this for a week and finally turning to you for help. Scripting is not my strong point :(

    The business needs an export of email addresses and object properties such as name and department from a distribution list - the export should only include properties of specific email domains.

    For example:

    Distribution list:  Marketing
    Users to export from Marketing:  All users with and all users with
    The distribution list contains email addresses from multiple domains
    Objects to export:  Name, Mail, Office, Department, Title
    To export to CSV.

    The below script works for exporting all staff from the distribution list, but not just for and addresses.

    This script works for exporting just and, but from the entire exchange environment, not just from the Marketing distribution list:
    get-aduser -filter {emailaddress -like "*" -or emailaddress -like "*"} -properties mail, description, title, office | select-object name,mail,office,department,title | export-csv -path c:\temp2\marketing.csv -notypeinformation

    The goal is to not have to filter data in Excel after the export.
    The output would then read:
    Tom Finnigan  Secretary  London  Administration
    Charlie O'Hara  Assistant  New York  Executive

    Any help would be really appreciated!

    • Edited by Chris_Jones_1 Thursday, March 17, 2016 4:52 AM fixed error for transparency
    Thursday, March 17, 2016 4:49 AM


  • This will give you a filtered list:
    	Get-ADUser -PropertiesMail,Description,Title,Office,Department|
    	Where{  $_.Mail -match '' } |
    	Select Name,Mail,Office,Department,Title 


    • Edited by jrv Thursday, March 17, 2016 5:07 AM
    • Marked as answer by Chris_Jones_1 Friday, March 18, 2016 3:42 AM
    Thursday, March 17, 2016 5:07 AM