Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.