Assigning Owner to Application Registration and Enterprise Application using PowerShell?

EnterpriseArchitect 4,896 Reputation points
2024-03-04T03:43:15.1033333+00:00

How can I use Microsoft PowerShell script to assign an Application or Service principal in Azure to a single user?

I have a list of the application names in a TXT file like below:

App1
WebApplication1
CloudApps1
....
App-X

However, when browsing the page I cannot find the cmdlet to add a set or even update:

https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.applications/get-mgapplicationowner?view=graph-powershell-1.0

Thank you in advance,

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,913 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,187 questions
Microsoft Entra
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,951 questions
{count} votes

Accepted answer
  1. CarlZhao-MSFT 38,196 Reputation points
    2024-03-04T06:45:25.5366667+00:00

    Hi @EnterpriseArchitect

    You can run the New-MgApplicationOwnerByRef cmdlet to add an owner to the target app.

    Import-Module Microsoft.Graph.Applications
    
    $params = @{
    	"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/{user id}"
    }
    
    New-MgApplicationOwnerByRef -ApplicationId $appObjectId -BodyParameter $params
    

    Or run the Remove-MgApplicationOwnerByRef cmdlet to remove the app owner.

    Hope this helps.

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


1 additional answer

Sort by: Most helpful
  1. Navya 4,860 Reputation points Microsoft Vendor
    2024-03-04T09:07:35.4866667+00:00

    Hi @EnterpriseArchitect

    Thank you for posting this in Microsoft Q&A.

    Adding to the above information provided by CarlZhao-MSFT.To add an owner to an Enterprise application using Microsoft Graph PowerShell.

    Connect-MgGraph -Scopes 'Application.ReadWrite.All'
    
    $owner = @{ 
    "@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
     } 
    
    New-MgServicePrincipalOwnerByRef -ServicePrincipalId $servicePrincipalId -BodyParameter $owner
    

    To get owners of the Enterprise Application use Get-MgServicePrincipalOwnerByRef

    To get owners of the Application Registration use Get-MgApplicationOwnerByRef

    Hope this helps. Do let us know if you any further queries.

    Thanks,

    Navya.