# Import pfx

**URL:** https://forums.powershell.org/t/import-pfx/11789
**Category:** DSC
**Created:** [December 13, 2018, 10:50am UTC](https://forums.powershell.org/t/import-pfx/11789 "2018-12-13T10:50:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![javidsalmanov](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@javidsalmanov](https://forums.powershell.org/u/javidsalmanov)
#### Post date: [December 13, 2018, 10:50am UTC](https://forums.powershell.org/t/import-pfx/11789/1 "2018-12-13T10:50:12Z")

</div>

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:

> **[Securing the MOF File - PowerShell](https://docs.microsoft.com/en-us/powershell/dsc/pull-server/secureMOF?view=dsc-1.1&viewFallbackFrom=powershell-7.2)**
>
> This article describes how to ensure the target node has encrypted the MOF file.

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

---

<div class="post-metadata">

### Author: ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)
#### Post date: [December 13, 2018, 11:47am UTC](https://forums.powershell.org/t/import-pfx/11789/2 "2018-12-13T11:47:58Z")

</div>

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](https://docs.microsoft.com/en-us/powershell/dsc/configdatacredentials)

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 9:16pm UTC](https://forums.powershell.org/t/import-pfx/11789/3 "2024-05-16T21:16:25Z")

</div>


