CertificateDsc icon indicating copy to clipboard operation
CertificateDsc copied to clipboard

DSC_CertReq failed to execute Set-TargetResource functionality with error message: Cannot add type. The type name 'Source.NativeMethods' already exists

Open heinejeppesen opened this issue 2 years ago • 0 comments

Problem description

I'm trying to upgrade our dev environments to Windows Server 2022 and I need to get certificate from a new WS2022 based PKI.

Deployment is through Azure DevOps pipeline and Azure Automation DSC on Azure VMs.

The error comes every time the pipeline runs, deploying from scratch. When looking at the DSC State in Azure Automation, the state becomes compliant at the second run, so almost immediately after pipeline has completed.

I can't force the error again, by testing manually, so I can't trigger the error once the initial deployment has succeeded. Log info is what I get returned from AZ CLI through the pipeline.

Everything works, but for some reason the DSC fails the initial runs but succeeds at second run.

Verbose logs

PowerShell DSC resource DSC_CertReq failed to execute Set-TargetResource functionality with error message: Cannot add type. The type name 'Source.NativeMethods' already exists

DSC configuration

#Check if a reboot is required before requesting certificates
        PendingReboot BeforeCertReq {
            Name             = "BeforeCertReq"
            DependsOn        = '[Script]ConfigureSendConnector'
        }

        ##Get Exchange Certificate
        CertReq SSLCert {
            Subject                 = "mail.$($domainName)"
            CAType                  = "Enterprise"
            KeyLength               = '2048'
            Exportable              = $true
            CertificateTemplate     = "$($environment)LabWebServer"
            SubjectAltName          = "dns=autodiscover.$($domainName)&dns=smtp.$($domainName)&dns=ews.$($domainName)"
            AutoRenew               = $true
            FriendlyName            = "mail.$($domainName)"
            Credential              = $domainAdminCredentialNetBios
            DependsOn               = "[PendingReboot]BeforeCertReq"
        }

Suggested solution

N/A

Operating system the target node is running

Server 2022 (unpatched at the failure time)

PowerShell version and build the target node is running

5.1 (Server 2022 built-in)

CertificateDsc version

5.1.0

heinejeppesen avatar Nov 18 '22 17:11 heinejeppesen