Import pfx

Hi, I’m trying to import pfx via DSC. My DSC code like that:

Configuration Main

{
    Import-DscResource -ModuleName xWebAdministration
    Import-DscResource -ModuleName xPSDesiredStateConfiguration
    Import-DscResource -ModuleName PSDesiredStateConfiguration
    Import-DSCResource -ModuleName xCertificate

    Node localhost
    {
		xPfxImport mycertCert {
            Thumbprint = 'ef0642af0b31974c0e0cc80dee4c4208fc4d4bc2'
            Path = "D:\Software\mycert.pfx"
            Store = 'My'
            Credential = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString -Key ([system.Text.Encoding]::UTF8).GetBytes("This is a string to hash") "76492d1116743f0423413b16050a5345MgB8AHkAYwBkAG4AMAAzAHoAVABUAHgARQBFAHQAWgBXAGEAWgBxAFgAawBXAGcAPQA9AHwANgA5ADgANAA1ADEAOABhADkAYgA2AGEANQBhADQANQA1AGMAOAA2AGIAMQA1ADkAYwA0AGIANwAzADgAMAAzADUAOQBkAGQAZg
BjAGIAOQA3ADUANAA="))
            Location = 'LocalMachine'
        }
      }
    }
    Main

I got this error:

ConvertTo-MOFInstance : System.InvalidOperationException error processing property ‘Credential’ OF TYPE ‘xPfxImport’: Converting and storing encrypted passwords as plain text is not recommended. For more information on securing credentials in MOF file, please refer to MSDN blog:

I need somehow pass cert password automatically. Any help would be welcome. Thanks in advance

Well , you can’t use credentials in a DSC resource by default. There are recommendation to do it. Please go through below documentation.

https://docs.microsoft.com/en-us/powershell/dsc/configdatacredentials