Powershell:如何将字节字符串与二进制注册表值进行比较 [英] Powershell: How to compare a byte string with a binary registry value
问题描述
我有一个二进制注册表值,我想在 Powershell 脚本中检查它的一致性.我正在通过以下方式检索值:
I have a binary registry value that I'd like to check for consistency in a Powershell script. I'm retrieving the value by:
(Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL
这将返回一个字节字符串作为结果.
This returns a byte string as a result.
然后我创建一个字节字符串变量,该变量与我期望的值相匹配,然后通过 regedit.exe 导出注册表项来查询该值.然后,我通过在由逗号分隔的每个字节前面加上0x"并键入 [byte] 来从该文本创建一个字节字符串.当我只观察两个字符串时,它们完全相同.但是,当我:
I then create a byte string variable that matches what I should expect then querying this value by exporting out the registry key through regedit.exe. I then create a byte string from that text by prepending "0x" in front of each byte separated by a comma and typing is a [byte]. When I just eyeball both strings they are exactly the same. However, when I:
$RegistryValue -eq $CreatedValue
他们不返回True.我做错了什么?
they don't return True. What am I doing wrong?
推荐答案
我终于通过我自己的一些不同方法和 Compare-Object cmdlet 的组合解决了这个问题.谢谢,达拉斯.
I finally figured this out by a combination of some different methods on my part and the Compare-Object cmdlet. Thanks, Dallas.
- 在注册表中设置适当的二进制值.
- 通过以下方式检索值:
$ValueItsSupposedToBe = (Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL
$ValueItsSupposedToBe = (Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL
创建一个逗号分隔的值字符串并将该字符串插入到比较脚本中.
Create a comma,separated string of the values and insert this string into the compare script.
在比较脚本中,拆分字符串并将其转换为字节数组.
In the compare script, split the string and convert it into a byte array.
[byte[]]$ValueItsSupposedToBe = $ValueItsSupposedToBe.Split(',')
[byte[]]$ValueItsSupposedToBe = $ValueItsSupposedToBe.Split(',')
- 读取另一台机器上当前设置的值.
$CompareValue = (Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL
$CompareValue = (Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL
- 如果 Compare-Object 返回 null,则它们相等.
比较对象 $CompareValue $ValueItsSupposedTobe
Compare-Object $CompareValue $ValueItsSupposedTobe
这篇关于Powershell:如何将字节字符串与二进制注册表值进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!