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