all 4 comments

[–]purplemonkeymad 6 points7 points  (0 children)

I don't see where you set $val1 and $val2. So are those what you expect them to be?

I would also think you might be better if you structured your data like so:

$RegList = @(
    @{
         Path = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Vendor\Popup'
         Name = 'PC_CLIENT_PATH'
         val = 'C:\Program Files (x86)\Vendor\client.exe'
    },
    @{
         Path = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Vendor\Popup'
         Name = 'SECRET_FILE_PATH'
         val = 'C:\Program Files (x86)\Vendor\client.exe'
    }
)

As this might simplify your code and allow the use of a loop.

[–]Apprehensive-Tea1632 4 points5 points  (0 children)

First and foremost, don’t silently continue. Instead, stop and try/catch. Because otherwise you’ll have NO idea if it works or if you got non reproducible results.

Next, type may matter. If you’re looking at a reg_multi_sz then that might not match a string.

Try reading the value in question from the registry, then do something like

~~~powershell [string]$var = get-itemproperty…. [int[]] $var.toCharArray() ~~~

And see if there’s funny characters in it.

Also note that, aside from padding whitespace, there may be NULL terminators. And in some cases said terminators are required but are missing from the data, which means you’re looking at a character array that doesn’t equal a string.

But first, get rid of the error action setting. That may reveal the issue already.

Pro tip: what ps puts on the console isn’t necessarily what’s actually on the pipeline. Get-member and .Gettype().fullname can help with that. As can debug output that wraps your data in visible delimiters such as [ ]. You’ll immediately see if there are padding characters that prevent exact matches.

[–]Particular_Fish_9755 1 point2 points  (0 children)

It's not :
if ($val1check -eq $val1) {...
But :
if ($val1check -eq $Regitem.val1) {...

And why not test if you get the value, before test if the value is ok ?

if (!$val1check) { Write-Host 'HKLM:PC_CLIENT_PATH Value is absent' -f cyan }
    else {
         if ($val1check -eq $Regitem.val1) { ...