Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Why can't I use a variable for a path?

$
0
0

Hi Guys,

I am writing a script that checks the value of a registry property. I first define a path to thelocation in the registry then try to get its value into a variable then test. Here's the snippet:


Powershell
$HKCU_myApp="HKCU:\Software\myApplication"$someArray# has list of installed applicationsIf($someArray-Match'App_123'){$pathToRegKey="$HKCU_myApp\App_123"# This is where it fails, if I replace $pathToRegKey with the literal path it works or if I replace $HKCU_myApp in the previous line, $pathToRegKey, with the literal path it works. I cannot concatenate $HKCU_myApp + $pathToRegKey$isLoggingEnabled=Get-ItemProperty$pathToRegKey-Name"DebugLog"Error:Get-ItemProperty:Cannotfindpath'HKCU:\Software\myApplication\App_123'becauseitdoesnotexist
The path does exist.
Thanks

Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>