automatically Assign ABP based on an attribute ( Exchange Online)

at the moment I run a daily task which runs some basic powershell scripts to filter users by an attribute and apply a different ABP.

For example

get-user -resultsize "unlimited" -Filter {(stateorprovince -eq "STANDARD") -and (city -ne "provisioned")} | %{Set-Mailbox $_.DistinguishedName -AddressBookPolicy "STANDARD_ABP" -WarningAction "silentlycontinue"}

get-user -resultsize "unlimited" -Filter {(Customattribute1 -eq "DOMAIN1") -and (city -ne "provisioned")} | %{Set-Mailbox $_.DistinguishedName -AddressBookPolicy "DOMAIN1_ABP" -WarningAction "silentlycontinue"}

get-user -resultsize "unlimited" -Filter {(Customattribute1 -eq "DOMAIN2") -and (city -ne "provisioned")} | %{Set-Mailbox $_.DistinguishedName -AddressBookPolicy "DOMAIN2_ABP" -WarningAction "silentlycontinue"}

this works fine, but I'm about to introduce 200+ domains, which would mean adding a repeated script for every single domain, most will want an individual ABP...although some are happy to Share the Standard ABP. 

Can this script be done in a better way? maybe calling a CSV and using some sort of function?

July 29th, 2015 8:15am

What is wrong with this:

get-user -resultsize "unlimited" -Filter {city -ne "provisioned"} | 
    %{
        Set-Mailbox $_.DistinguishedName -AddressBookPolicy $_.CustomAttribute1
    }

This wouold do all in one pass.  We should also filter out those that are already assigned which wouold also run faster.

Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 8:41am

Perfect, Thank you....but how would i deal with users that do not have a Customattribute set but use the stateorprovince attribute instead?

all users have a code in stateorprovince, but those users that want the standard ABP have an extra attribute set in CustomAttribute1
July 29th, 2015 9:06am

Filter for them separately just like you are now.

Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 9:19am

Works a treat, I now only have two line for all domains!!

here's what I've got now

get-user -resultsize "unlimited" -Filter {(city -ne "provisioned") -and (Customattribute1 -ne "STANDARDABP")} | %{Set-Mailbox $_.DistinguishedName -AddressBookPolicy $_.Stateorprovince}

get-user -resultsize "unlimited" -Filter {(Customattribute1 -eq "STANDARDABP")} | %{Set-Mailbox $_.DistinguishedName -AddressBookPolicy $_.CustomAttribute1}

Thanks again

July 29th, 2015 10:50am

Great. It should be faster too.
Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 10:54am

Perfect, Thank you....but how would i deal with users that do not have a Customattribute set but use the stateorprovince attribute instead?

all users have a code in stateorprovince, but those users that want the standard ABP have an extra attribute set in CustomAttribute1
  • Edited by Mtdmitchell2 Wednesday, July 29, 2015 1:04 PM added info
July 29th, 2015 1:02pm

Perfect, Thank you....but how would i deal with users that do not have a Customattribute set but use the stateorprovince attribute instead?

all users have a code in stateorprovince, but those users that want the standard ABP have an extra attribute set in CustomAttribute1
  • Edited by Mtdmitchell2 Wednesday, July 29, 2015 1:04 PM added info
Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 1:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics