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

Vinay Sharma 56 Reputation points
2022-09-28T15:23:57.18+00:00

Hi all,
I tried following the document: https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth but unable to get through this step: https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#register-service-principals-in-exchange.

When following : Register service principals in Exchange

I am trying to execute the command as mentioned in the document but facing New-ServicePrincipal : The term 'New-ServicePrincipal' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Below is the screenshot of the issue
245605-image.png

Could anyone please help me out on this.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} vote

Accepted answer
  1. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2022-09-28T16:37:49.497+00:00

    Ensure you have the right perms for this account. When in doubt, verify you have the Exchange Admin/Org Mgmt role.
    The min perm needed is "Role Management"

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

    Role RoleAssigneeType RoleAssigneeName
    ---- ---------------- ----------------
    Role Management RoleGroup Organization Management

    https://learn.microsoft.com/en-us/powershell/exchange/find-exchange-cmdlet-permissions?view=exchange-ps

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Jame Xu-MSFT 4,191 Reputation points
    2022-09-29T08:03:34.73+00:00

    Hi @Vinay Sharma ,
    You may need to assign sufficient permissions to run 'New-ServicePrincipal'. The relevant commands to find permissions are given by Andy.
    245983-image.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    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.

    2 people found this answer helpful.

  2. Vukasin Terzic 351 Reputation points MVP
    2022-09-28T15:48:41.833+00:00

    Hello @Vinay Sharma ,

    New-ServicePrincipal cmdlet is part of ExchangeOnline module and if that command is not found, it is probably because you don't have that module installed or properly imported.

    You can verify that by running Get-Module command and looking at installed modules.

    In case you didn't find it, try repeating this steps:

    Install-Module -Name ExchangeOnlineManagement -allowprerelease  
    Import-module ExchangeOnlineManagement   
    

    And finally, you can find more information about that PowerShell module here: https://learn.microsoft.com/en-us/powershell/module/exchange/?view=exchange-ps

    Please let us know if you need anything else or if this helped you resolve your issue.

    Thank you,

    Vukasin

    1 person found this answer helpful.

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.