Facing issue while Encrypting Credentials in DSC MOF Files

Hi ,

I have Installed Windows Management Framework (WMF) 5.0 RTM edition that was released 2015-12-17 to encrypt the Credentials in DSC MOF Files. but while try to create the mof, i was getting the error shown below .

Dsc script
$ConfigData= @{
AllNodes = @(
@{
# The name of the node we are describing
NodeName = “localhost”

                        # The path to the .cer file containing the 
                        # public key of the Encryption Certificate 
                        # used to encrypt credentials for this node"
                        CertificateFile ="C:\Publickeys\Pullserver.cer"


                        # The thumbprint of the Encryption Certificate 
                        # used to decrypt the credentials on target node 
                        Thumbprint ="7af113abe96aede262fe965983248dd533306d7f"
                    }; 
                );    
} 


configuration test 

{
param( 
    [Parameter(Mandatory=$true)] 
    [ValidateNotNullorEmpty()] 
    [PsCredential] $credential 
    ) 

           
    Import-DscResource -ModuleName PSDesiredStateConfiguration -ModuleVersion 1.1
node  $AllNodes.NodeName
{
      File exampleFile 
    { 
        SourcePath = "\\sptest\C\devcon\devcontest.txt”
        DestinationPath = "\\sptest\C\credsencrpt" 
        Credential = $credential 
    } 
  
  
      LocalConfigurationManager 
    { 
         CertificateId = $node.Thumbprint
       
    } 
}
}

test -configurationdata $ConfigData -outputpath c:\credsencrpt

Error :

PS C:\Windows\system32> C:\credsencrpt\creden.ps1
cmdlet test at command pipeline position 1
Supply values for the following parameters:
ConvertTo-MOFInstance : System.Management.Automation.RuntimeException error processing property ‘Credential’ OF TYPE ‘File’: Method invocation failed because
[Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache] does not contain a method named ‘GetStringFromSecureString’.
At C:\credsencrpt\creden.ps1:32 char:11

  • File
    At line:297 char:16
  • $aliasId = ConvertTo-MOFInstance $keywordName $canonicalizedValue
    
  •            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:slight_smile: [Write-Error], InvalidOperationException
    • FullyQualifiedErrorId : FailToProcessProperty,ConvertTo-MOFInstance
      WARNING: It is not recommended to use domain credential for node ‘localhost’. In order to suppress the warning, you can add a property named ‘PSDscAllowDomainUser’ with a value of $t
      rue to your DSC configuration data for node ‘localhost’.
      WARNING: The configuration ‘test’ is loading one or more built-in resources without explicitly importing associated modules. Add Import-DscResource –ModuleName ‘PSDesiredStateConfigu
      ration’ to your configuration to avoid this message.
      Errors occurred while processing configuration ‘test’.
      At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3705 char:5
  • throw $ErrorRecord
    
  • ~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (test:String) [], InvalidOperationException
    • FullyQualifiedErrorId : FailToProcessConfiguration

So please guide me to resolve this issue .

You want to use WMF 5.0 RTM re-released in Feb instead of Dec one @ https://www.microsoft.com/en-us/download/details.aspx?id=50395.
I tried it and compilation is succeeding.

You want to use WMF 5.0 RTM re-released in Feb instead of Dec one @ https://www.microsoft.com/en-us/download/details.aspx?id=50395.
I tried it and compilation is succeeding.

I have installed the latest version which mentioned above , but i was facing the issue .

Seems like somehow you end up using old SMA.dll instead of the one from WMF 5.0 RTM. Can you restart your machine and try again? I will also try to find the root cause.