Hello John,
Thank you for clarifying. Use the below scripts to grant the permissions. In the scripts, the $mailboxIdentity specifies the name of the mailbox for which a user will be granted the permissions. To run the scripts you need to create Custom Commands configured for User object type. To grant a user the required permissions you will need to execute the corresponding command for them. To have a possibility to grant both permissions at the same time, you can create another Custom Command that will execute both commands for a user.
Script granting Send As permissions
$mailboxIdentity = "OnlineMailbox" # TODO: modify me
try
{
# Get the object ID in Office 365
$objectId = ([Guid]$Context.TargetObject.Get("adm-O365ObjectId")).ToString()
}
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/" -Authentication Basic -AllowRedirection -Credential $Context.GetOffice365Credential()
Import-PSSession $session -CommandName "Get-Mailbox", "Add-RecipientPermission"
# Grant permissions
try
{
Add-RecipientPermission -Trustee $objectId -AccessRight "SendAs" -Confirm:$False -ErrorAction Stop -Identity $mailboxIdentity
}
catch
{
$Context.LogMessage("An error occurred when adding permissions to mailbox $mailboxIdentity. Error: " + $_.Exception.Message, "Warning")
return
}
}
finally
{
# Close the remote session and release resources
if ($session) { Remove-PSSession $session }
}
Script granting Full Access permissions
$mailboxIdentity = "OnlineMailbox" # TODO: modify me
try
{
# Get the object ID in Office 365
$objectId = ([Guid]$Context.TargetObject.Get("adm-O365ObjectId")).ToString()
}
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/" -Authentication Basic -AllowRedirection -Credential $Context.GetOffice365Credential()
Import-PSSession $session -CommandName "Get-Mailbox", "Add-MailboxPermission"
# Grant permissions
try
{
Add-MailboxPermission -Deny:$False -User $objectId -AccessRights "FullAccess" -ErrorAction Stop -Identity $mailboxIdentity
}
catch
{
$Context.LogMessage("An error occurred when adding permissions to mailbox $mailboxIdentity. Error: " + $_.Exception.Message, "Warning")
return
}
}
finally
{
# Close the remote session and release resources
if ($session) { Remove-PSSession $session }
}