无法在LCM的元配置中存储SMB拉取服务器的加密凭据(PS 4.0)

时间:2017-11-22 18:31:36

标签: powershell credentials powershell-v4.0 dsc

我是DSC的新手,我已经尝试了几天,让我的元配置与SMB拉服务器配合使用,但无济于事。

上下文:

  • 目标节点是Win 2012 R2服务器,同一域的成员
  • 我只能使用PS 4.0
  • 我无法向拉服务器上的SMB共享中的每个人提供读取权限
  • 我不希望拉模式依赖自定义模块才能正常运行(仅限PS 4.0安装)
  • 我的创作节点目前是我的测试目标节点
  • 我尝试使用New-SelfsignedCertificateEx.ps1但无法让它在我的Windows 7上运行
  • 我正在使用在Windows 10上生成的带有请求的KU和EKU的自签名证书
  • 我的元配置适用于没有凭据的SMB共享(由测试目标节点本身托管/授予每个人的读访问权限)

我一直在网上搜索,但只找到代码示例或有关传递给DSC资源的凭据的问题。我还没有找到PS 4.0代码的示例,其中实时PSCredential对象(从Get-Credential cmdlet检索)即时加密到元配置mof。

我试图转换大量示例(包括来自herehere),但我无法加密我的凭据,并且每次都会收到这条知名消息:

ConvertTo-MOFInstance : System.InvalidOperationException error processing property 'Credential' OF TYPE 'LocalConfigurationManager': 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: 
http://go.microsoft.com/fwlink/?LinkId=393729
At line:190 char:16
+     $aliasId = ConvertTo-MOFInstance $keywordName $canonicalizedValue
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessProperty,ConvertTo-MOFInstance
Errors occurred while processing configuration 'MetaConfigurationForPull'.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2223 char:5
+     throw $errorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (MetaConfigurationForPull:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

这是我的代码:

# Getting credentials for filer connection (CIFS share for pulling MOF files)
$cred = Get-Credential -Message 'Provide credentials for CIFS share hosting configuration files:'

Configuration MetaConfigurationForPull {
    Param (
        [PSCredential] $Credential
    )

    LocalConfigurationManager {
        ConfigurationID = "f28a102c-71c9-43a1-abbb-a944ec7cb5cd";
        CertificateID = $AllNodes.Thumbprint;
        Credential = $Credential;
        RefreshMode = "PULL";
        RebootNodeIfNeeded = $false;
        DownloadManagerName = "DscFileDownloadManager";
        DownloadManagerCustomData = @{SourcePath = '\\smb_pull_server\smb_share\mofs\batch_server'};
    }
}

$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 = "D:\node_rdp_cert.cer"

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

MetaConfigurationForPull -Credential $cred -ConfigurationData $ConfigData -Output "D:\meta\batch_server"

我还发现that post谈到PS 5.0上的一些回归,而且这个家伙说他在PS 4.0上的所有功能都像魅力一样。

我在上面的代码中遗漏了什么?
任何帮助将不胜感激。

由于

1 个答案:

答案 0 :(得分:0)

只要这只是一个测试环境,您就可以添加:

PSDscAllowPlainTextPassword = $true

到你的配置。

示例:here