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

Anna He 20 Reputation points
2023-08-01T05:47:38.9233333+00:00

I'm trying to register service principal in Exchange following instructions in https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth. I'm connecting to Exchange Online from my Windows Powershell, but encountered the CommandNotFoundException when running New-ServicePrincipal.

I can confirm that I connected succesfully since Get-mailbox command does work. I did find someone encountered the same in this thread: https://learn.microsoft.com/en-us/answers/questions/1027098/facing-new-serviceprincipal-the-term-new-servicepr, I do have app administrator role in Microsoft Azure, so not sure if it's a perms issue. I tried running the Get-ManagementRole command suggested in the answer, but this also gives me the same error "The term 'Get-ManagementRole' is not recognized as the name of a cmdlet, function, script file, or operable program"

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,184 questions
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 119.7K Reputation points MVP Volunteer Moderator
    2023-08-01T06:33:51.8433333+00:00

    It's a permission issue, your Azure admin role does not translate to admin role in Exchange Online. Talk to your M365 admin/IT desk to grant you the necessary permissions, or ask them to create the service principal on your behalf.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yuki Sun-MSFT 41,376 Reputation points Moderator
    2023-08-02T06:53:47.6+00:00

    Hi @Anna He ,

    Yes, it sounds like a permission issue.

    I tried following this document to find out the permission required for New-ServicePrincipal, the output shows that the Role Management role is required and by default it's only assigned to the Organization Management role:
    User's image

    The Get-ManagementRole command you mentioned also needs the Role Management role according to this link.

    So, in summary, you would need to contact your global admin or others who manage the role assignment to add your account to the Organization Management role group.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

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.