Results comparison


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] 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:

Get-DistributionGroup -Filter {Alias -like "*-reports"}Get-DistributionGroup -Filter {Alias -like "*-reports"}

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?




If you like to compare objects you should read the help for Compare-Object. :wink:

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 “” 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?

If that’s all you’re asking for … :wink: … with a calculated property you can achieve this very easily

Get-ADUser -SearchBase ‘OU=Managers,DC=Contoso,DC=Com’ -Filter “DirectReports -like ‘*’” |
Select-Object -Property *,@{Name=‘Estimated-DDL-Name’;Expression={$_.sAMAccountName + ‘’}}

Of course you have to change the -SearchBase to fit to your environment. :wink:

This is exactly what I needed, thank you so much for the assist, Olaf!