Office 365: How to impersonate a service account in Exchange Online!

As happens in Exchange OnPremises, it’s possible to impersonate a service account in Exchange Online (EXO) so third party tools can use account permisssions to perform operations in EXO. In order to impersonate a service account in EXO you will need to execute a PowerShell script similar to the following one:

$sUserName="<O365User>@<O365Domain>.onmicrosoft.com"
$sMessage="Introduce your O365 Credentials"
$Cred=Get-Credential -UserName $sUserName -Message $sMessage
#Configure a Group to use classification:
$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $PSSession

Get-ManagementRoleAssignment 

Enable-OrganizationCustomization
$sAccountToBeImpersonated="<ServiceAccount>@<O365Domain>.onmicrosoft.com"
$sImpersonationScopeName="<Your Impersonation Scope Name>"
New-ManagementRoleAssignment -name:$sImpersonationScopeName -Role:ApplicationImpersonation -User:$sAccountToBeImpersonated

Reference:

Office 365: Como impersonar una cuenta de servicio en Exchange Online!

En Exchange Online al igual que en Exchange OnPremises es posible impersonar una cuenta de servicio de forma que por ejemplo desde una aplicación de terceros pueda usar los permisos de la cuenta impersonada. Para poder impersonar una cuenta de servicio en Exchange Online necesitaréis ejecutar la siguiente secuencia de comandos PowerShell:

$sUserName="<O365User>@<O365Domain>.onmicrosoft.com"
$sMessage="Introduce your O365 Credentials"
$Cred=Get-Credential -UserName $sUserName -Message $sMessage
#Configure a Group to use classification:
$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $PSSession

Get-ManagementRoleAssignment 

Enable-OrganizationCustomization
$sAccountToBeImpersonated="<ServiceAccount>@<O365Domain>.onmicrosoft.com"
$sImpersonationScopeName="<Your Impersonation Scope Name>"
New-ManagementRoleAssignment -name:$sImpersonationScopeName -Role:ApplicationImpersonation -User:$sAccountToBeImpersonated

Referencia: