Reputation: 4198
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.
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
they don't return True. What am I doing wrong?
Upvotes: 2
Views: 5536
Reputation: 4198
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
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(',')
$CompareValue = (Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL
Compare-Object $CompareValue $ValueItsSupposedTobe
Upvotes: 1
Reputation: 320
Try using the compare-object cmdlet.
Compare-Object $RegistryValue $CreatedValue
If they're equal, you should see the ==
operator in the results table.
Upvotes: 5