Skip to content

Instantly share code, notes, and snippets.

@weeyin83
Created January 3, 2020 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weeyin83/7f7dec01983d1d246f9e53f15e67871a to your computer and use it in GitHub Desktop.
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
# 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