Get-ItemPropertyValue Property 2 does not exist path

Hi
when I using:

$val=Get-ItemPropertyValue ‘HKLM:\SYSTEM\Keyboard Layout\Preload’ -name ‘2’ -ErrorAction ignore

or

Get-ItemPropertyValue ‘HKLM:\SYSTEM\Keyboard Layout\Preload’ -name ‘2’ -ErrorAction ignore

I get an error that the “Get-ItemPropertyValue : Property 2 does not exist”

I need do to “if” the value exist then…

Is there a way to do it?

Firstly, when posting code, data, and errors in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

How to format code on PowerShell.org

You could do it with try/catch error handling:

try {
    Get-ItemPropertyValue -Path 'HKLM:\SYSTEM\Keyboard Layout\Preload' -Name '2'
    # Do stuff if property exists.
}
catch {
    # Do stuff if property doesn't exist.
}