0

I am currently using a PowerShell to connect to Azure AD through Connect-AzureAD with Certificate and SPN. This is the part of my script where i create a self signed certificate, export to my local store on my machine and load it afterwards:

$thumb = (New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName com.foo.bar -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $notAfter).Thumbprint
$pwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
Export-PfxCertificate -cert "cert:\localmachine\my\$thumb" -FilePath $certPath -Password $pwd

# Load the certificate
$cert  = New-Object System.Security.Cryptography.X509Certificates.X509Certificate($certPath, $pwd)
$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData())

The problem is how to do this in VSTS Online with a similar PowerShell script? Is there also such a cert store? I have already an existing .pfx which i need to use, a creation of a new one is not neccessary.

STORM
  • 4,005
  • 11
  • 49
  • 98

1 Answers1

0

Refer to this thread to import pfx file to store: Visual studio team services deploymen/buildt certificate error

  $pfxpath = 'pathtoees.pfx'
    $password = 'password'

    Add-Type -AssemblyName System.Security
    $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
    $cert.Import($pfxpath, $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet")
    $store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser
    $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite")
    $store.Add($cert)
    $store.Close()
starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53