locked
automatically Assign ABP based on an attribute ( Exchange Online) RRS feed

  • Question

  • 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?

    Wednesday, July 29, 2015 12:10 PM

Answers

  • 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.


    \_(ツ)_/

    • Marked as answer by Mtdmitchell2 Wednesday, July 29, 2015 1:19 PM
    Wednesday, July 29, 2015 12:36 PM
  • Filter for them separately just like you are now.


    \_(ツ)_/

    • Marked as answer by Mtdmitchell2 Wednesday, July 29, 2015 1:19 PM
    Wednesday, July 29, 2015 1:14 PM

All replies

  • 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.


    \_(ツ)_/

    • Marked as answer by Mtdmitchell2 Wednesday, July 29, 2015 1:19 PM
    Wednesday, July 29, 2015 12:36 PM
  • 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
    Wednesday, July 29, 2015 1:02 PM
  • Filter for them separately just like you are now.


    \_(ツ)_/

    • Marked as answer by Mtdmitchell2 Wednesday, July 29, 2015 1:19 PM
    Wednesday, July 29, 2015 1:14 PM
  • 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

    Wednesday, July 29, 2015 2:45 PM
  • Great. It should be faster too.

    \_(ツ)_/

    Wednesday, July 29, 2015 2:50 PM