Last active
January 30, 2019 23:14
-
-
Save jkbryan/d391a15226a5cb08d86c1dac451a3538 to your computer and use it in GitHub Desktop.
Creates an Azure Service Principle named <AppName> in the Subscription
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
$Subscription = "<Subscription-GUID>" | |
$PathToPFXCertificate = "C:\<PATH>\<CertName>.pfx" | |
$PFXPassword = "<Password>" | |
$CertPassword = ConvertTo-SecureString $PFXPassword -AsPlainText -Force | |
$ApplicationName = "<AppName>" | |
Import-Module AzureRM.Resources | |
Connect-AzureRmAccount | |
Set-AzureRmContext -Subscription $Subscription | |
$PFXCert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($PathToPFXCertificate, $CertPassword) | |
$KeyValue = [System.Convert]::ToBase64String($PFXCert.GetRawCertData()) | |
$ServicePrincipal = New-AzureRMADServicePrincipal -DisplayName $ApplicationName | |
New-AzureRmADSpCredential -ObjectId $ServicePrincipal.Id -CertValue $KeyValue -StartDate $PFXCert.NotBefore -EndDate $PFXCert.NotAfter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment