Avatar of ndalmolin_13
ndalmolin_13
Flag for United States of America asked on

Help using test-path to check for the existence of a registry key in Powershell

Hello All,

I'm trying to test for the existence of a registry key using the test-path command.  Here is what I'm doing:
test-path -Path 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F66F74D4-ACF1-48EE-BF6F-2C6629581859}'

I know for a fact this exists, but the test-path is coming up as "False".

Any help would be appreciated.

Thanks,
Nick
Powershell

Avatar of undefined
Last Comment
footech

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Seth Simmons

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
footech

Note - you can actually use the full path as in regedit if you prepend it with "registry::", for example:
test-path -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F66F74D4-ACF1-48EE-BF6F-2C6629581859}'

Open in new window


Or if you're already in the registry drive, so that the cmdlet knows to use the registry provider, your original command will work.
cd hklm:\
test-path -Path 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F66F74D4-ACF1-48EE-BF6F-2C6629581859}'

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck