Jump to content

Recommended Posts

Posted

I have a script I would like to run hourly to place users in the correct OU. It works now, but is fairly slow as it goes over every user and tries to assign them to the ABP, even if it is already set. I am unsure how to improve the code so it checks if AddressBookPolicy is already set... I have used Get-User as I need to lookup Company / Department, and this does not allowpull through AddressBookPolicy as a filter item.

 

 

 

Get-User -ResultSize unlimited -Filter "company -eq 'Trust'" | foreach {Set-Mailbox -Identity $_.MicrosoftOnlineServicesID -AddressBookPolicy "Trust"}

 

Get-User -ResultSize unlimited -Filter {(UserPrincipalName -like "*@schooldomain.co.uk") -and (Department -ne "Governor") -and (RecipientType -eq "UserMailBox")} | foreach {Set-Mailbox -Identity $_.MicrosoftOnlineServicesID -AddressBookPolicy "SchoolABP"}

 

Get-User -ResultSize unlimited -Filter {(UserPrincipalName -like "*@schooldomain.co.uk") -and (Department -eq "Governor") -and (RecipientType -eq "UserMailBox")} | foreach {Set-Mailbox -Identity $_.MicrosoftOnlineServicesID -AddressBookPolicy "GovernorABP"}

Posted

Haven't tested it as we don't have those identities like company filled in, but couldn't you just use recipient as they have access to both company and ABP

 

Something like:

 

Get-Recipient -Filter "(RecipientType -eq 'UserMailbox')" | Where-Object {($_.Company -eq "Trust") -and ($_.AddressBookPolicy -eq $null)}

 

Or:

 

Get-Recipient -Filter "(RecipientType -eq 'UserMailbox') -and (Company -eq 'Trust') -and (AddressBookPolicy -notlike '*')"  

 

Steve

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...