Created
January 3, 2020 11:04
-
-
Save weeyin83/7f7dec01983d1d246f9e53f15e67871a to your computer and use it in GitHub Desktop.
Create an Azure Service Principal with Contributor access to a single resource group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create the Service Principal, generates a random password, grants the Service Principal Contributor access to only a single resource group | |
$sp = New-AzADServicePrincipal -DisplayName ServicePrincipalName -Role Contributor -Scope /subscriptions/zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz/resourceGroups/myResourceGroup | |
# Export the random password that was generated on creation | |
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sp.Secret) | |
$UnsecureSecret = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) | |
$UnsecureSecret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment