I need to maintain a list of dynamic distribution lists for every manager in my organization. All the groups should have the naming standard of [SAMAccountName]-reports@domain.com. To start, I pull a list of managers with this one-liner:
Get-ADUser -Filter "DirectReports -like '*'"
I can also pull a list of existing dynamic groups with this one-liner:
The question is, how can I compare these two search results to come up with a delta that I can easily tack on a foreach statement and create groups that may not have been created yet?
This definitely looks like something I can make use of, if I whip it hard enough…
As I try to mentally plan out how to approach this, I see a challenge in producing usable results. Get-ADUser will give me anything I need from an AD account but I don’t rightly know what comparable info I can pull using Get-DistributionGroup. I suppose if I could add “-reports@domain.com” to the end of the SAMAccountName resulting from Get-ADUser it would be easy as pie but lo, I am but a simple PS peasant… Any thoughts on how to approach this?