Skip to content

Instantly share code, notes, and snippets.

@jkbryan
Last active August 19, 2020 23:30
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 jkbryan/8f41fc26ec89be1717c1b44ea7d51e1a to your computer and use it in GitHub Desktop.
Save jkbryan/8f41fc26ec89be1717c1b44ea7d51e1a to your computer and use it in GitHub Desktop.
# Login first
Login-AzAccount
# Note that you can optionally assign an Azure role on creation,
# define the context prior to SP creation, using Set-AzContext
#
# Create Service Principle
$sp = New-AzADServicePrincipal -Role Reader -DisplayName "MyServicePrinciple"
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sp.Secret)
$UnsecureSecret = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# Write out the password for the SP. Make sure you keep a secure copy of this output!
Write-Host $UnsecureSecret
#
# Assuming that you want to get the SP's AppID or ObjectID after creation:
Get-AzADServicePrincipal -DisplayNameBeginsWith "myserv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment