Skip to content

Instantly share code, notes, and snippets.

@tomzorz
Created June 7, 2018 14:38
Show Gist options
  • Save tomzorz/35d795e144d7814fca57ff43c9b435d3 to your computer and use it in GitHub Desktop.
Save tomzorz/35d795e144d7814fca57ff43c9b435d3 to your computer and use it in GitHub Desktop.
Create Azure Service Principal
# set params
$subid = '{subscription id here}'
$uri = 'http://{uri here}'
$pp = '{password here}'
$dn = '{display name here}'
# ----------------------------------------------
# run code
Login-AzureRmAccount -SubscriptionId $subid
$password = ConvertTo-SecureString $pp -asplaintext -force
$app = New-AzureRmADApplication -DisplayName $dn -HomePage $uri -IdentifierUris $uri -Password $password
New-AzureRmADServicePrincipal -ApplicationId $app.ApplicationId
# wait 30 sec before executing below
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $app.ApplicationId
# your ClientId
$app.ApplicationId
# your ClientSecret
$pp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment