Created
September 15, 2019 20:14
-
-
Save staslebedenko/82950c701ae0e23ac444173f6266d31a to your computer and use it in GitHub Desktop.
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
Connect-AzureRmAccount | |
$vaultname="yourFancyVault" | |
$certname="SomeCertName" | |
$certpw="SuperPassword" | |
$groupname="your-fabric-group" | |
$clustername = "your-cluster-name" | |
$ExistingPfxFilePath="C:\certificates\SomeCertName.pfx" | |
$appcertpwd = ConvertTo-SecureString -String $certpw -AsPlainText -Force | |
Write-Host "Reading pfx file from $ExistingPfxFilePath" | |
$cert = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 $ExistingPfxFilePath, $certpw | |
$bytes = [System.IO.File]::ReadAllBytes($ExistingPfxFilePath) | |
$base64 = [System.Convert]::ToBase64String($bytes) | |
$jsonBlob = @{ | |
data = $base64 | |
dataType = 'pfx' | |
password = $certpw | |
} | ConvertTo-Json | |
$contentbytes = [System.Text.Encoding]::UTF8.GetBytes($jsonBlob) | |
$content = [System.Convert]::ToBase64String($contentbytes) | |
$secretValue = ConvertTo-SecureString -String $content -AsPlainText -Force | |
Write-Host "Writing secret to $certname in vault $vaultname" | |
$secret = Set-AzureKeyVaultSecret -VaultName $vaultname -Name $certname -SecretValue $secretValue | |
Add-AzureRmServiceFabricApplicationCertificate -ResourceGroupName $groupname -Name $clustername -SecretIdentifier $secret.Id -Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment