【发布时间】:2017-01-13 21:38:42
【问题描述】:
我已经使用 1.1 和 xScript 5.1.0.0 的内置脚本资源对此进行了测试,并获得了相同的结果。我的 Set 和 Test 块工作正常。我正在使用其他几个非常相似的脚本资源,它们也适用于 get 块。
我尝试了很多不同的语法变化,但结果总是一样。我知道该块正在运行,因为我注释掉了创建的文件被删除的行并且我看到了该文件。我还在 powershell 中将其作为函数运行,并将输出通过管道传输到 Get-Member,可以看到它确实是一个返回的 hastable。
顺便说一句,我真的不喜欢我在这里使用的通过 DSC 管理此设置的方法。我对其他想法持开放态度,只要它仍在 DSC 中。
Script StorePasswordsUsingReversibleEncyption
{
SetScript = {
secedit /export /cfg c:\temp\secpol.cfg
(gc C:\temp\secpol.cfg).replace("ClearTextPassword = 1", "ClearTextPassword = 0") | Out-File C:\temp\secpol.cfg
secedit /configure /db c:\windows\security\local.sdb /cfg c:\temp\secpol.cfg /areas SECURITYPOLICY /quiet
rm -force c:\temp\secpol.cfg -confirm:$false
}
TestScript = {
secedit /export /cfg c:\temp\secpol.cfg
$str = (Get-Content 'c:\temp\secpol.cfg' | select-String 'ClearTextPassword' -SimpleMatch).ToString()
rm -force c:\temp\secpol.cfg -confirm:$false
if ($str -eq 'ClearTextPassword = 0') {return $true}
else {return $false}
}
# Not working yet
GetScript = {
secedit /export /cfg c:\temp\secpol.cfg
$str = (Get-Content 'c:\temp\secpol.cfg' | select-String 'ClearTextPassword' -SimpleMatch).ToString()
rm -force c:\temp\secpol.cfg -confirm:$false
return @{Result = $str}
}
}
运行 Get-DSCConfiguration 后,控制台返回的输出是这样的:
Get-DscConfiguration : PowerShell DSC resource MSFT_ScriptResource failed to execute Get-TargetResource functionality
with error message: Failure to get the results from the script in a hash table format.
At line:1 char:1
+ Get-DscConfiguration
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (MSFT_DSCLocalConfigurationManager:root/Microsoft/...gurationManager)
[Get-DscConfiguration], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure,Get-DscConfiguration
【问题讨论】:
标签: powershell hashtable dsc