How do I create a Powershell command to link the attribute 'City' in AD to a DL in Exchange and then auto add Users created for this location?

I need help with a Powershell command.

So we have several of these working already working with our AD to Office 365 - Exchange environment.

It is a powershell command that looks to an Attribute in AD - called City - of which picks up in this case florida.

This in turn adds the User to a DL - called AllFloridaUsers in our cloud Exchange environment in Office 365.
Darrin CrawfordAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alex Green3rd Line Server SupportCommented:
Get-aduser -filter "CIty -like 'Florida'" -searchbase "Enter DN of searchbase" -properties City  | Add-adgroupmember -groupname AllFloridaUsers


I'd put the search base in so you don't affect accounts you shouldn't do.
0
Vasil Michev (MVP)Commented:
If your groups are created directly in O365, here's an updated variant:

Get-User -Filter {City -eq "Sofia"} | % { Add-DistributionGroupMember AllFloridaUsers -Member $_.UserPrincipalName  }

Open in new window

0
Darrin CrawfordAuthor Commented:
Thanks guys, unfortunately getting errors with both - for first one, not recognizing Ad-AddGroupMember....  The second one is giving errors around 'Member' , saying it is null
0
Do You Have a Trusted Wireless Environment?

A Trusted Wireless Environment is a framework for building a complete Wi-Fi network that is fast, easy to manage, and secure.

Vasil Michev (MVP)Commented:
Well, did you change the City name, I used "Sofia" to test it with my users :)
0
Darrin CrawfordAuthor Commented:
How do I edit this on Exchange through Powershell?


((((((((((((((((((((((RecipientTypeDetails -eq 'UserMailbox') -and (RecipientTypeDetails -eq 'UserMailbox'))) -and (City -eq 'Florida'))) -and (-not(CustomAttribute1 -eq 'Contractor')))) -and (-not(Name -like 'SystemMailbox{*')))) -and (-not(Name -like 'CAS_{*')))) -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')))) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')))) -and (-not(Name -like 'SystemMailbox{*')) -and (-not(Name -like 'CAS_{*')) -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')
0
Darrin CrawfordAuthor Commented:
Yeah Vasil - I changed the name
0
Vasil Michev (MVP)Commented:
The cmdlet runs just fine for me:

Get-User -Filter {City -eq "Sofia"} | % { Add-DistributionGroupMember DG -Member $_.UserPrincipalName -WhatIf }
What if: Adding distribution group member "HuKu@michev.onmicrosoft.com" on distribution group "DG".
What if: Adding distribution group member "pesho@michev.info" on distribution group "DG".

Open in new window


Do you get any results for the filter? Can you shown an example of what the City attribute looks like for said users?

If you want to use a Dynamic DG, you need this query:

Set-DynamicDistributionGroup DDG -RecipientFilter {((RecipientTypeDetails -eq 'UserMailbox') -and (City -eq 'Florida') -and (-not(CustomAttribute1 -eq 'Contractor')))}

Open in new window


The rest will be added automatically.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Darrin CrawfordAuthor Commented:
Thanks - that is exactly what i was looking for :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.