Registry Address appends with folder address, throws error ?!

touqeeranjum 80 Reputation points
2023-02-02T22:30:14.5166667+00:00

Hi,

I have the below code which adds a newKey in the Registry, then adds Property and Value to the Key.

$reg = "Registry::\"

$keyPath = Join-Path -Path $reg -ChildPath 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures'

$keyPath

$regPath = New-item -Path $keyPath -Name "010103000F0000F0A00000000F0000F02C87FF61F728E3750B595CBC8787E88B96F707107614712C139EE8F64A2CFB3C"

$regPath.Name

New-ItemProperty -Path $regPath.Name -Name "NetworkName" -Value "DOMAIN" -PropertyType String

Which results in the below output:

PS C:\Users\Administrator\Desktop\Configuration> $reg = "Registry::\"

PS C:\Users\Administrator\Desktop\Configuration> $keyPath = Join-Path -Path $reg -ChildPath 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures'

PS C:\Users\Administrator\Desktop\Configuration> $keyPath

Registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures

PS C:\Users\Administrator\Desktop\Configuration> $regPath = New-item -Path $keyPath -Name "010103000F0000F0A00000000F0000F02C87FF61F728E3750B595CBC8787E88B96F707107614712C139EE8F64A2CFB3C"

PS C:\Users\Administrator\Desktop\Configuration> $regPath.Name

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\010103000F0000F0A00000000F0000F02C87FF61F728E3750B595CBC8787E88B96F707107614712C139EE8F64A2CFB3C

New-ItemProperty : Cannot find path

'C:\Users\Administrator\Desktop\Configuration\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows NT\Cur

rentVersion\NetworkList\Signatures\010103000F0000F0A00000000F0000F02C87FF61F728E3750B595CBC8787E88B96F707107614712C139E

E8F64A2CFB3C' because it does not exist.

At line:1 char:1

+ New-ItemProperty -Path $regPath.Name -Name "NetworkName" -Value "DOMA ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The variable $regPath.Name results in the absolute path of the Key as in the code above, when I pass it to the next command for some reason its appending the $regPath.Name value with C:\Users\Administrator\Desktop\Configuration\HKEY_LOCAL_MACHINE address instead of parsing it as a registry address.

Any idea what's going on ?

Thank You

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,546 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,577 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. touqeeranjum 80 Reputation points
    2023-02-03T08:48:32.8+00:00

    Got this working.

    Its suppose to be $regPath.PSPath instead of $regPath.Name

    New-ItemProperty -Path $regPath.PSPath -Name "NetworkName" -Value "DOMAIN" -PropertyType String
    
    0 comments No comments

  2. touqeeranjum 80 Reputation points
    2023-02-03T08:49:11.1266667+00:00

    Got this working.

    Its suppose to be $regPath.PSPath instead of $regPath.Name

    New-ItemProperty -Path $regPath.PSPath -Name "NetworkName" -Value "DOMAIN" -PropertyType String

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.