Skip to content

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

@heinejeppesen

Description

@heinejeppesen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions