Вот пример из документации:
$AutomationAccountName = "<automation account name>"
$PfxCertPath = '<PFX cert path'
$CertificatePassword = '<password>'
$certificateName = '<certificate name>'
$AutomationAccountName = '<automation account name>'
$flags = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable `
-bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet `
-bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet
# Load the certificate into memory
$PfxCert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($PfxCertPath, $CertificatePassword, $flags)
# Export the certificate and convert into base 64 string
$Base64Value = [System.Convert]::ToBase64String($PfxCert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12))
$Thumbprint = $PfxCert.Thumbprint
$json = @"
{
'`$schema': 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#',
'contentVersion': '1.0.0.0',
'resources': [
{
'name': '$AutomationAccountName/$certificateName',
'type': 'Microsoft.Automation/automationAccounts/certificates',
'apiVersion': '2015-10-31',
'properties': {
'base64Value': '$Base64Value',
'thumbprint': '$Thumbprint',
'isExportable': true
}
}
]
}
"@
$json | out-file .\template.json
New-AzureRmResourceGroupDeployment -Name NewCert -ResourceGroupName TestAzureAuto -TemplateFile .\template.json
в основном вам нужно экспортировать его с паролем, используя System.Security.Cryptography:
# Load the certificate into memory
$PfxCert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($PfxCertPath, $CertificatePassword, $flags)
# Export the certificate and convert into base 64 string
$Base64Value = [System.Convert]::ToBase64String($PfxCert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12))
и затем вы можете передать его в шаблон base64Value
свойство
https://docs.microsoft.com/en-us/azure/automation/shared-resources/certificates#creating-a-new-certificate