I am working on automating the deployment of our product on Azure VMs. I am using Powershell DSC with Azure automation to provision the VM.
One of the requirement is to import a pfx certificate to CurrentUser/My for a user on the VM. I am trying to do this using the following Script resource:
Script InstallSelfSignedCertificatesToMy
{
GetScript = {
}
SetScript = {
$Path = "c:\test"
$Pass = ConvertTo-SecureString "password"-AsPlainText -Force
Import-PfxCertificate -FilePath "$($Path)\example.pfx" cert:\currentUser\my -Password $Pass
}
TestScript = {
return $false
}
Credential = $adminCredential
}
The $adminCredential parameter has the credentials for the user where I want to import the certificate.
This DSC does not report any failure but the certificate is not added to the CurrentUser/My on the user.
One interesting observation is that if I run the DSC locally on the VM using Start-DscConfiguration it works as expected and the certificates get installed. It does not work if called from Azure Automation.
Can anyone point out what may be the issue here? Has anyone tried to do something similar?
Thanks in advance.
Invoke-PfxCertificate
have this as an exported command? Is there a way you could log this attempt or put the Import statement in a try/catch with some output of the exception? – Pulmonate