Created
July 15, 2019 08:55
-
-
Save jeevan-vj/faef220b215ec988aaefdfdbf8801588 to your computer and use it in GitHub Desktop.
Create Service Principal in Powershell and login to azure
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 AD app | |
$dummyUrl = "https://dummy.dummy.com" | |
$passpowrd = "Qwerty@123!" | |
$securePassword = ConvertTo-SecureString -String $passpowrd -AsPlainText -Force | |
$app = New-AzureRmADApplication -DisplayName $dummyUrl ` | |
-IdentifierUris $dummyUrl ` | |
-HomePage $dummyUrl ` | |
-Password $securePassword -Verbose | |
#Create Service principal | |
New-AzureRmADServicePrincipal -ApplicationId $app.ApplicationId ` | |
-DisplayName $dummyUrl ` | |
-Password $securePassword ` | |
-Scope "/subscriptions/<SUBSCRIPTION ID>" ` | |
-Role Contributor ` | |
-StartDate ([datetime]::Now) ` | |
-EndDate $([datetime]::now.AddYears(1)) -Verbose | |
#Login with service principal | |
$clientId = "<CLIENT ID>" | |
$credentials = New-Object System.Management.Automation.PSCredential ($clientId, $securePassword) | |
Login-AzureRmAccount -ServicePrincipal -TenantId "<TENANTID>" ` | |
-SubscriptionId "<SUBSCRIPTIONID>" ` | |
-Credential $credentials |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment