Hello,
Thank you for clarifying. We recommend the following solution:
- Update permissions for all existing mailboxes in Windows PowerShell using the below script. When prompted, enter the credentials of the account that was used to register your Office 365 tenant in Adaxes.
try
{
# Connect to Exchange Online
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" `
-Credential (Get-Credential) -Authentication Basic -AllowRedirection
Import-PSSession $session -AllowClobber -DisableNameChecking -CommandName "Add-MailboxPermission", "Get-Mailbox"
# Change mailbox type
Get-Mailbox -ResultSize unlimited | Add-MailboxPermission -User "company administrator" -AccessRights 'FullAccess'
}
finally
{
# Close the remote session and release resources
if ($session) { Remove-PSSession $session }
}
- Use the Scheduled Task to update the permissions only for new users. You will need to mark the users by setting a specific property value. For example, you can set an Adaxes custom Boolean attribute (e.g. CustomAttributeBoolean1) to True after assigning Office 365 licenses in a Business Rule triggering After Creating a User. The Scheduled Task will run the script only for users that have the attribute set to true and have a mailbox. Also, the Scheduled Task will clear the attribute.
The Business Rule will look like the following:
The Scheduled Task in its turn will look like the following and use the below script:
try
{
# Get the object ID in Office 365
$objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
return # The user doesn't have an Office 365 account
}
try
{
# Connect to Exchange Online
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" `
-Credential $Context.GetOffice365Credential() -Authentication Basic -AllowRedirection
Import-PSSession $session -AllowClobber -DisableNameChecking -CommandName "Add-MailboxPermission"
# Change mailbox type
Add-MailboxPermission $objectId.ToString() -User "company administrator" -AccessRights 'FullAccess'
}
finally
{
# Close the remote session and release resources
if ($session) { Remove-PSSession $session }
}