1
votes

when we create an azure ad app registration from the azure portal the service principal is automatically created, and given a contributors role, how do we achieve the same using PowerShell ?

I tried running the following the command the app is created but no service principal is created, and there are no parameters for configuring a service principle

New-AzADApplication -DisplayName "NewApplication" -HomePage "http://www.microsoft.com" -IdentifierUris "http://NewApplication" 

what i am looking for is to create the following using powershell, is this possible ?

  1. AzureADAppregistration + ServicePrincipal
  2. Create and get the client secret

Thanks

1
You need to use New-AzureADServicePrincipal to create the SPjuunas
How's going? Has your issue got resolved? Let me know if you have any questionsStanley Gong

1 Answers

3
votes

Try this:

#set your secret here.    
$secretTextValue = "abcdefg1234567890" 

$secret = ConvertTo-SecureString -String $secretTextValue -AsPlainText

$app = New-AzADApplication -DisplayName "NewApplication" -HomePage "http://www.microsoft.com" -IdentifierUris "http://NewApplication" 

New-AzADAppCredential -ObjectId $app.ObjectId -Password $secret -EndDate (Get-Date).AddMonths(6)
    
#azure will assign contributor role of current subscription to this SP
New-AzADServicePrincipal -ApplicationId $app.ApplicationId 

Result:

enter image description here

enter image description here

enter image description here