Skip to content

Instantly share code, notes, and snippets.

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 staslebedenko/82950c701ae0e23ac444173f6266d31a to your computer and use it in GitHub Desktop.
Save staslebedenko/82950c701ae0e23ac444173f6266d31a to your computer and use it in GitHub Desktop.
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