Question

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?

Was it helpful?

Solution 2

I finally figured this out by a combination of some different methods on my part and the Compare-Object cmdlet. Thanks, Dallas.

  1. Set the appropriate binary value in the registry.
  2. Retrieve the value via:

$ValueItsSupposedToBe = (Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL

  1. Create a comma,separated string of the values and insert this string into the compare script.

  2. In the compare script, split the string and convert it into a byte array.

[byte[]]$ValueItsSupposedToBe = $ValueItsSupposedToBe.Split(',')

  1. Read the value currently set on another machine.

$CompareValue = (Get-ItemProperty -Path HKLM:\Software\ORL\WinVNC3 -Name ACL).ACL

  1. If Compare-Object comes back as null, then they're equal.

Compare-Object $CompareValue $ValueItsSupposedTobe

OTHER TIPS

Try using the compare-object cmdlet.

Compare-Object $RegistryValue $CreatedValue

If they're equal, you should see the == operator in the results table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top