1

I'am trying to check the value of registry keys and show if the path is present and if they key has a certain value:


#$ErrorActionPreference = "silentlycontinue"
Function checkRegistry($path,$name,$description,$target){
if((Get-ItemPropertyValue -LiteralPath $path -Name $name) -ne $null) {
    if((Get-ItemPropertyValue -LiteralPath $path -Name $name) -eq $target) {
        Write-Host -NoNewline "Correct:" $description  
    } else {
        Write-Host -NoNewline "False:" $description 
    }
}
else  {                    
      Write-Host -NoNewline "No Registry Path of:"  $description
}
}
checkRegistry("\HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsUpdate\UX\Settings\","SmartActiveHoursState","Windows Update Active Hours","2")

But I always get:

Get-ItemPropertyValue : Cannot bind argument to parameter 'Name' because it is null. At line:3 char:52 + if((Get-ItemPropertyValue -LiteralPath $path -Name $name) -ne $null) ... + ~~~~~ + CategoryInfo : InvalidData: (:) [Get-ItemPropertyValue], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetItemPropertyValueCommand
LS1989
  • 11
  • 1
  • 1
    PowerShell functions must not be called with parentheses. You are actually passing an array of 4 strings for the 1st parameter of `checkRegistry`. Thus, it's complaining about `Name` being null. To fix, call `checkRegistry` with command syntax like this: `checkRegistry -Path "…" -Name "…" -Description "…" -Target "…" ` – zett42 Jul 07 '23 at 16:27
  • Wow that mistake happens a lot. – js2010 Jul 07 '23 at 18:26
  • `Set-StrictMode -Version latest` would catch that, "The function or command was called as if it were a method. Parameters should be separated by spaces." – js2010 Jul 10 '23 at 14:21

0 Answers0