Facing: New-ServicePrincipal : The term 'New-ServicePrincipal' is not recognized as the name of a cmdlet, function, script file, or operable program.

Paweł Mrzygłód 0 Reputation points

Im trying to setup xoauth2 for our helpdesk aplication.

Im following below commands to configure exchange.

Install-Module -Name ExchangeOnlineManagement

Install-Module Microsoft.Graph

Install-Module -Name AzureAD

import-module AzureAD

Import-module ExchangeOnlineManagement

Connect-AzureAd -Tenant “TenantID”

Connect-ExchangeOnline -Organization “TenantID”

$MyApp = Get-AzureADServicePrincipal -SearchString “YourAppName”

New-ServicePrincipal -AppId $MyApp.AppId -ServiceId $MyApp.ObjectId -DisplayName "Service Principal for IMAP APP"

Add-MailboxPermission -Identity "alkampfer@gianmariaricci.onmicrosoft.com" -User $MyApp.ObjectId -AccessRights FullAccess

Do you have any ideas why New-ServicePrincipal cmdlet is not working?

A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,851 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 43,926 Reputation points

    Do you have sufficient permissions to run that cmdlet? Do you hold one of these Exchange roles: Exchange Admin oar Organization Managment?


    0 comments No comments

  2. Limitless Technology 43,971 Reputation points

    Hello there,

    Ensure you have the right perms for this account. When in doubt, verify you have the Exchange Admin/Org Mgmt role.

    The minmum permisson needed is "Role Management"

    $Perms = Get-ManagementRole -Cmdlet New-ServicePrincipal

    $Perms | foreach {Get-ManagementRoleAssignment -Role $_.Name -Delegating $false | Format-Table -Auto Role,RoleAssigneeType,RoleAssigneeName}

    Similar discussion here https://learn.microsoft.com/en-us/answers/questions/1027098/facing-new-serviceprincipal-the-term-new-servicepr

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments