Rajiv
Rajiv

Reputation: 685

RegKey Value in to a variable in PowerShell

I have the below code snippet:

$Reg2 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Machine)
 $RegKey2= $Reg.OpenSubKey("SOFTWARE\\TrendMicro\\PC-cillinNTCorp\\CurrentVersion\\Misc.")
 $CheckAVVer = $RegKey2.GetValue("ProgramVer")

Whats happening is $CheckAVVer doesn't seem to grab the value. If remove the $CheckAVVer, it works and displays the value.

Please help.

Upvotes: 1

Views: 97

Answers (1)

malexander
malexander

Reputation: 4700

In the second line, change:

$Reg.OpenSubKey("SOFT...

To:

$Reg2.OpenSubKey("SOFT...

And see if that fixes it for you.

$Reg2 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Machine)
$RegKey2= $Reg2.OpenSubKey("SOFTWARE\\TrendMicro\\PC-cillinNTCorp\\CurrentVersion\\Misc.")
$CheckAVVer = $RegKey2.GetValue("ProgramVer")
Write-host $CheckAVVer

Upvotes: 1

Related Questions