query and compare reg-multi-sz value and path

Hi guys,

i need to query and compare reg-multi-sz value and path multiple times so i have created a function

#Function for check of Registry Key Value is like parameter
function AuditRegistryKeyValue ($RegKeyPath,$RegKeyName,$RegKeyValue,$Description)
    {
        $Response=((Get-ItemProperty -Path $RegKeyPath -Name $RegKeyName).$RegKeyName)
        If ($Response -like $RegKeyValue)
             {
                write-host $RegKeyPath
               write-host $RegKeyValue
             }
        Else
             {
                write-host $RegKeyPath
                write-host $RegKeyValue

       }
     }

The $Response and $RegKeyValue are optical the same - but it always goes in the else loop. Why? If I'm not comparing reg-multi-sz it works. I know that reg-multi-sz contains line breaks.

Example:
    $Description = "Network access: Remotely accessible registry paths and sub-paths"
    AuditRegistryKeyValue -RegKeyPath "hklm:System\CurrentControlSet\Control\SecurePipeServers\Winreg\AllowedPaths" -RegKeyName Machine -RegKeyValue "System\CurrentControlSet\Control\Print\Printers"+`n+"System\CurrentControlSet\Services\Eventlog Software\Microsoft\OLAP Server Software\Microsoft\Windows NT\CurrentVersion\Print Software\Microsoft\Windows NT\CurrentVersion\Windows System\CurrentControlSet\Control\ContentIndex System\CurrentControlSet\Control\Terminal Server System\CurrentControlSet\Control\Terminal Server\UserConfig System\CurrentControlSet\Control\Terminal Server\DefaultUserConfiguration Software\Microsoft\Windows NT\CurrentVersion\Perflib System\CurrentControlSet\Services\SysmonLog" -Description $Description

Any ideas? Thank you and kind regards

Peter

July 22nd, 2015 9:06am

You cannot use "like" to match an array too a string.

Use Compare to compare two arrays. If the compare returns nothing then the arrays are identical.

$a=2,4,6
$b=2,4,6
if(compare $a $b){'arrays dont match'}else{'arrays match'}

$a=2,4,6
$b=2,1,6
if(compare $a $b){'arrays dont match'}else{'arrays match'}

You can capture the results of the compare and see exactly what is different.

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 9:58am

Hi jrv,
thanks for help. This was the solution...
Kind regards

Peter

July 27th, 2015 2:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics