none
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 @work1.com and all users with @work2.com
    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 @work1.com and @work2.com addresses.
    Get-ADGroupMember-Identity"Marketing"-Recursive|Get-ADUser-PropertiesMail,Description,Title,Office,Department|Select-ObjectName,Mail,Office,Department,Title|Export-CSV-PathC:\temp\marketing.csv-NoTypeInformation

    This script works for exporting just @work1.com and @work2.com, but from the entire exchange environment, not just from the Marketing distribution list:
    get-aduser -filter {emailaddress -like "*work1.com" -or emailaddress -like "*work2.com"} -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  tom@work1.com  Secretary  London  Administration
    Charlie O'Hara  charlie@work2.com  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

Answers

  • This will give you a filtered list:
    Get-ADGroupMember-Identity"Marketing"-Recursive|
    	Get-ADUser -PropertiesMail,Description,Title,Office,Department|
    	Where{  $_.Mail -match '@work1.com' } |
    	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