Powershell 从DSC脚本资源导入CurrentUser Personal Store中的pfx证书+;自动化不起作用

Powershell 从DSC脚本资源导入CurrentUser Personal Store中的pfx证书+;自动化不起作用,powershell,pfx,dsc,azure-automation,Powershell,Pfx,Dsc,Azure Automation,我正致力于在Azure虚拟机上自动部署我们的产品。我正在使用Powershell DSC和Azure automation来配置VM 要求之一是为VM上的用户将pfx证书导入CurrentUser/My。我正在尝试使用以下脚本资源执行此操作: Script InstallSelfSignedCertificatesToMy { GetScript = { } SetScript = {

我正致力于在Azure虚拟机上自动部署我们的产品。我正在使用Powershell DSC和Azure automation来配置VM

要求之一是为VM上的用户将pfx证书导入CurrentUser/My。我正在尝试使用以下脚本资源执行此操作:

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
       }
$adminCredential参数具有要导入证书的用户的凭据

此DSC不报告任何故障,但证书未添加到用户的CurrentUser/My

一个有趣的观察结果是,如果我使用Start DscConfiguration在VM上本地运行DSC,它将按预期工作,并安装证书。如果从Azure Automation调用,它将不起作用

有人能指出这里的问题是什么吗?有人试过做类似的事情吗


提前感谢。

此代码似乎在$Pass=ConvertTo SecureString“password”-AsPlainText-Force中使用了“password”而不是$adminCredential。这是一个打字错误吗?很抱歉,不清楚-“password”是证书pfx文件的密码,而$adminCredential是计算机上的本地管理员用户凭据。我正在运行模拟此用户访问其个人证书存储的脚本。您运行的
Invoke PfxCertificate
环境是否将此作为导出命令?是否有一种方法可以记录此尝试或将Import语句放入带有异常输出的try/catch中?