locked
Script to interrogate AD for users with a few different job titles & then hide them in the GAL RRS feed

  • Question

  • I have a list of job titles that I need to hide in my GAL, I have managed to work out how to collect users from one job title and output it to a CSV:

    Get-ADUser -Filter "Title -like 'Trainee'" -Prop Title | Export-Csv c:\Temp\HideUsers.csv 

    But I can't do it for multiple roles into the same CSV, can anyone advise?

    Then once I have that CSV I need to utilise it to run the following command for all the users in the CSV:

    Set-ADUser import-csv c:\Temp\HideUsers.csv -Replace @{msExchHideFromAddressLists=$true}

    If the above is the right syntax?!

    Any help gratefully received! 

    Thanks,

    Glenn


    Tuesday, January 14, 2020 3:57 PM

Answers

  • Expanding on JRV's answer, and answering your question about how collect users with several different titles:

    Get-ADUser -Filter {(Title -eq 'Trainee') -or (Title -eq 'Goat Herder') -or (Title -eq 'Supreme Commander')} |
         Set-ADUser -Replace @{msExchHideFromAddressLists=$true}
    As JRV noted, there's no need for an intermediary CSV file to accomplish the task.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by Richard MuellerMVP Tuesday, January 14, 2020 9:06 PM
    • Marked as answer by jrv Tuesday, January 21, 2020 3:03 AM
    Tuesday, January 14, 2020 4:21 PM

All replies

  • LIKE only works with a wildcard.  Set ADUser cannot take input from a Csv file.  "Properties" are not used for filters.

    Get-ADUser -Filter "Title -eq 'Trainee'" |
         Set-ADUser -Replace @{msExchHideFromAddressLists=$true} 


    \_(ツ)_/


    • Edited by jrv Tuesday, January 14, 2020 4:11 PM
    Tuesday, January 14, 2020 4:11 PM
  • Expanding on JRV's answer, and answering your question about how collect users with several different titles:

    Get-ADUser -Filter {(Title -eq 'Trainee') -or (Title -eq 'Goat Herder') -or (Title -eq 'Supreme Commander')} |
         Set-ADUser -Replace @{msExchHideFromAddressLists=$true}
    As JRV noted, there's no need for an intermediary CSV file to accomplish the task.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by Richard MuellerMVP Tuesday, January 14, 2020 9:06 PM
    • Marked as answer by jrv Tuesday, January 21, 2020 3:03 AM
    Tuesday, January 14, 2020 4:21 PM
  • Thanks!
    Wednesday, January 15, 2020 8:32 AM
  • This is exactly what I needed, cheers! (And nice job titles!)
    Wednesday, January 15, 2020 8:33 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Lee

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, January 21, 2020 3:02 AM