Connect-OrganizationAddInService using Entra ServicePrincipal ID

Juan Perez 0 Reputation points
2024-04-25T20:01:49.8666667+00:00

I am trying to find if someone has successfully done this, basically automatize the deployment of an Add-in to Office 365

  • Client Secret: "1111111111111111111" (This is a secret that should be protected and not shown, I am having a look how to improve this)
  • APP ID: "2222222222222222222222222"
  • TenantID : "333333333333333333333333"

Followed:

https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps

Created a Microsoft Entra App and added:

  • Office 365 Exchange Online and Exchange.ManageAsAPP API Permissions
  • In Microsoft Entra roles and administrators, Exchange Administrator added MSOfficeAddon Princial App

I tried the below, but not working

Import-Module -Name O365CentralizedAddInDeployment
Install-Module -Name O365CentralizedAddInDeployment

$clientSecret = "1111111111111111111" 
$appId = "2222222222222222222222222"
$tenantId = "333333333333333333333333"

$secureStringPwd = $clientSecret | ConvertTo-SecureString -AsPlainText -Force
$psCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList
$appId, $secureStringPwd
Connect-OrganizationAddInService -Credential $psCredential

Then two different outcomes errors

  • Connect-OrganizationAddInService : The Organization Add-In Service session was not initialized. Please call the Connect-OrganizationAddInService commandlet first.
  • OrganizationAddInService : The user name or password is incorrect. Verify your user name, and then type your password again.

I tested the PSCredentials and worked

Connect-AzAccount -ServicePrincipal -Credential $psCredential -Tenant $tenantId
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,590 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
549 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,561 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 108.2K Reputation points MVP
    2024-04-26T07:14:55.96+00:00

    Afaik the corresponding endpoint only supports delegate permissions, you cannot connect via a service principal.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.