我有以下所需的状态配置 (DSC)
Configuration Cert
{
param (
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[System.String] $machineName,
[Parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$certCredential
)
Import-DscResource -ModuleName xPSDesiredStateConfiguration, xCertificate
Node $machineName
{
xPfxImport cert
{
Ensure = 'Present'
Path = 'C:\certificate.pfx'
Thumbprint = 'abcdefg'
Location = 'LocalMachine'
Store = 'My'
Exportable = $true
Credential = $certCredential
}
}
}
$cd = @{
AllNodes = @(
@{
NodeName = 'localhost'
PSDscAllowPlainTextPassword = $true
}
)
Run Code Online (Sandbox Code Playgroud)
}
$secpasswd = ConvertTo-SecureString 'password' -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ('x', $secpasswd)
Cert -machineName MyPC -certCredential $mycreds -ConfigurationData $cd
Start-DscConfiguration –Path .\Cert –Wait –Verbose -Force
Run Code Online (Sandbox Code Playgroud)
当我尝试执行此操作时,出现以下错误:
ConvertTo-MOFInstance : System.InvalidOperationException 错误处理属性 'Credential' OF TYPE 'xPfxImport':不建议将加密密码转换和存储为纯文本。有关在 MOF 文件中保护凭据的详细信息,请参阅 MSDN 博客:http : //go.microsoft.com/fwlink/?LinkId=393729 在 C:\Users\x\Desktop\script.ps1:18 char:9 + xPfxImport At line:341 char:16 + $aliasId = ConvertTo-MOFInstance $keywordName $canonicalizedValue + ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (: ) [Write-Error], InvalidOperationException +fullyQualifiedErrorId : FailToProcessProperty,ConvertTo-MOFInstance 处理配置“证书”时发生编译错误。请查看错误流中报告的错误并适当修改您的配置代码。在 C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3917 char:5 + throw $ErrorRecord + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Cert:String) [],
我意识到密码必须加密,并且不允许或至少不建议将其保存为普通密码。我已经尝试了互联网上提出的许多建议,但仍然无法使其正常工作。
我正在寻找一种安装证书并在此之后授予某些设置证书权限的方法。
您需要允许plaintextcredentials
(链接)
Configuration DomainCredentialExample
{
param(
[PSCredential]$DomainCredential
)
Import-DscResource -ModuleName PSDesiredStateConfiguration
Node $AllNodes.NodeName
{
Group DomainUserToLocalGroup
{
GroupName = 'InfoSecBackDoor'
MembersToInclude = 'contoso\notyouraccount'
Credential = $DomainCredential
}
}
}
$cd = @{
AllNodes = @(
@{
NodeName="localhost"
PSDscAllowPlainTextPassword=$true
}
)
}
$cred = Get-Credential -UserName contoso\genericuser -Message "Password please"
DomainCredentialExample -DomainCredential $cred -ConfigurationData $cd
Run Code Online (Sandbox Code Playgroud)
发现自己面临同样的问题,我只是想我会重申问题的实际原因(实际上隐藏在评论中):
最后一条评论把我引向了真正的问题。我没有意识到节点名实际上是导致问题的原因。请将节点 localhost 行 (8) 更改为 Node $AllNodes.NodeName 并将 NodeName="*" 改回 NodeName="localhost"
挑选里面的框架代码PSDesiredStateConfiguration.psm1
,PSDscAllowPlainTextPassword
除非$machineName = localhost
(在我们的例子中,它实际上是完全限定与非完全限定机器名称的情况),否则不会看到标志。
我也偶然发现了一个未记录的解决方法(不是我一定推荐使用它) - 实际上可以使用以下注册表项关闭对纯文本凭据的检查:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\DSC]
"PSDscAllowPlainTextPassword"="True"
"PSDscAllowDomainUser"="True"
Run Code Online (Sandbox Code Playgroud)
希望这可以让其他人免于头疼!
归档时间: |
|
查看次数: |
2762 次 |
最近记录: |