Bird
0
0

How can you use Test-Path to check if a registry key exists?

hard📝 Application Q9 of 15
PowerShell - File and Directory Operations
How can you use Test-Path to check if a registry key exists?
Example: Check if HKCU:\Software\MyApp exists.
ATest-Path 'HKCU:\Software\MyApp'
BTest-Path -Registry 'HKCU:\Software\MyApp'
CTest-Path -Key 'HKCU:\Software\MyApp'
DTest-Path -PathType Registry 'HKCU:\Software\MyApp'
Step-by-Step Solution
Solution:
  1. Step 1: Understand Test-Path supports registry paths

    Test-Path can check registry keys by passing the registry path as a string.
  2. Step 2: Identify correct syntax

    Test-Path 'HKCU:\Software\MyApp' uses the correct syntax. Other options use invalid parameters.
  3. Final Answer:

    Test-Path 'HKCU:\Software\MyApp' -> Option A
  4. Quick Check:

    Registry path as string works with Test-Path = Test-Path 'HKCU:\Software\MyApp' [OK]
Quick Trick: Test-Path accepts registry paths as strings [OK]
Common Mistakes:
  • Using unsupported parameters like -Registry
  • Assuming Test-Path only works on file system

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes