Assign predefined Office 365 services to a user

It can be very tedious to assign specific services within a license to many users in Office365, because you will have to enter the Office 365 admin area, search for the user, add the country, add the license and then remove all the services that the user should not have. “Oh wait which one were those again?” Snap… Now you have to open your reference to check which services you were supposed to use again and so on and so on…

There is a better way. This PowerShell script will assign a license to a user, set the region and disable certain services within the O365 license.

##################################################
# Login to Exchange
##################################################

$Credential = Get-Credential
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid" -Credential $credential -Authentication "Basic" -AllowRedirection

##################################################
# Remove and re-add user to shared mailbox with 
# "Full Access" without automapping enabled
##################################################

# Enter all the users here
$users = @( "<email-1@example.com>"; "<email-2@example.com>"; "<email-3@example.com>" )

# Enter the shared mailbox here
$sharedmail = "<shared_email@example.com>"

# Run the operation
Import-PSSession $ExchangeSession
$users | % {Remove-MailboxPermission -Identity $sharedmail -User $_ -AccessRights FullAccess -Confirm:$false}
$users | % {Add-MailboxPermission -Identity $sharedmail -User $_ -AccessRight FullAccess -InheritanceType All -Automapping $false}
$users | % {Add-RecipientPermission $sharedmail -AccessRights SendAs -Trustee $_ -Confirm:$false}

# Adds "Copy items sent as this mailbox" and "Copy items sent on behalf of this mailbox" for the shared mail box
Set-Mailbox $sharedmail -MessageCopyForSentAsEnabled $True
Set-Mailbox $sharedmail -MessageCopyForSendOnBehalfEnabled $True

Get-PSSession | Remove-PSSession

If we go to the Office 365 admin panel we can see the results after a couple of minutes. image