lara400
lara400

Reputation: 4736

registry key error

The below registry folder has two keys within it - they are entitled:

Name: 1 Data: somedate (REG_SZ) Name: 2 Data: somedata (REG_SZ)

The name of the keys are called "1" and "2". This is causing me issues in powershell when trying to use each of the keys as Powershell thinks something is wrong.

So, I first find the Property of the keys:

$acceptedsnmppackets = Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers | Select-Object -ExpandProperty Property

Then when I want to use one of the keys to get the value out of them by doing the below:

$acceptedsnmppackets1 = $(Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers).1

I get an error of the below:

Unexpected token '.1' in expression or statement.
At :line:108 char:120
+                         $(Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers).1 <<<< 

When I do this somewhere else in the code with another key that actualy has a name instead of a character then it works fine. The "1" and "2" are causing me issues and I cannot change the name of the keys.

All I want to do is to read what data each key has.

Any ideas?

Thanks,

Upvotes: 0

Views: 249

Answers (1)

Shay Levy
Shay Levy

Reputation: 126702

Does this help?

$path = 'HKLM:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers'
(Get-ItemProperty -Path $path -Name 1).'1'

Upvotes: 1

Related Questions