注册表DSC失败,带有BINARY / HEX值

时间:2017-07-11 11:03:49

标签: powershell dsc

撕掉我的头发...我试图通过DSC设置一个注册表键值,但我尝试的一切都失败了。使用原生PSDesiredStateConfiguration资源和REGISTRY

问题是我要设置的值必须在REG_BINARY中,且值也在HEX中。尝试了多种方式添加Hex = $true并在每个Hex字符串的开头添加所有“0x” - 它们似乎都不适合我。即使尝试了以下但仍然失败(Hex在下面被引用,但是尝试打开和关闭并且不为我工作)...对此有任何帮助

Registry SNMPServiceFail {
    Ensure      = "Present"
    Key         = "HKLM:\SYSTEM\CurrentControlSet\Services\SNMPTRAP"
    Force       = $true
    ValueName   = "FailureActions"
    ValueData   = @([byte[]](0x80,0x51,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x14,0x00,0x00,0x00,01,0x00,0x00,0x00,0xe0,0x93,0x04,0x00))
    ValueType   = "Binary" 
    #Hex = $true
}

错误:

VERBOSE: [LONINENGD187]: LCM:  [ Start  Resource ]  [[Registry]SNMPServiceFail]
VERBOSE: [LONINENGD187]: LCM:  [ Start  Test     ]  [[Registry]SNMPServiceFail]
VERBOSE: [LONINENGD187]:                            [[Registry]SNMPServiceFail] (ERROR) Parameter 'ValueData' has an
invalid value '(128, 81, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 1, 0, 0, 0, 224, 147, 4, 0)' for type
'Binary'
VERBOSE: [LONINENGD187]: LCM:  [ End    Test     ]  [[Registry]SNMPServiceFail]  in 1.5310 seconds.
PowerShell DSC resource MSFT_RegistryResource  failed to execute Test-TargetResource functionality with error message:
(ERROR) Parameter 'ValueData' has an invalid value '(128, 81, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0,
1, 0, 0, 0, 224, 147, 4, 0)' for type 'Binary'
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

VERBOSE: [LONINENGD187]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

当我进行注册表导出时,它显示如下 - 这就是我要确保它在所有服务器上设置为:

"FailureActions"=hex:80,51,01,00,00,00,00,00,00,00,00,00,01,00,00,00,14,00,00,00,01,00,00,00,e0,93,04,00

1 个答案:

答案 0 :(得分:2)

Registry resource期望ValueData输入为字符串数组,然后在内部将其转换为字节数组(请参阅链接源文件中的ConvertTo-Binary函数)。

转换为[string[]]而不是[byte[]]

Registry SNMPServiceFail {
    Ensure      = "Present"
    Key         = "HKLM:\SYSTEM\CurrentControlSet\Services\SNMPTRAP"
    Force       = $true
    ValueName   = "FailureActions"
    ValueData   = @([string[]](0x80,0x51,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x14,0x00,0x00,0x00,01,0x00,0x00,0x00,0xe0,0x93,0x04,0x00))
    ValueType   = "Binary"
}