You never provided any errors about your attempt, which would have provided you with relevant information about your issue that would have helped you (and us) to solve the issue.
But in short; No, your code wont work.
Your are on the right track though. If you read all the comments you would end with a code something like this...
# Define the path to the registry key
$RegistryPath = 'HKCU:\SOFTWARE\OurCompany\PricerApp\ABCProxy'
# Create the registry key
New-Item -Path $RegistryPath -Force
# Set a new value within the recreated registry key
$NewKey1 = @{
Path = $RegistryPath
Name = 'Enable'
Value = 3
PropertyType = 'DWORD'
}
New-ItemProperty @NewKey1
$NewKey2 = @{
Path = $RegistryPath
Name = 'RetryAttempts'
Value = 5
PropertyType = 'DWORD'
}
New-ItemProperty @NewKey2
# Verify the change
Get-ItemProperty -Path $RegistryPath
I changed the example path to be able to test it without being a local admin.
You can of course enter the values not using the technique of splatting (providing the parameters as a hash table). Splatting increases code readability but also, to some degree, the complexity.
New-ItemProperty -Path <value> -Name <value> -Value <value> -PropertyType <type>
Most often for pedagogic reasons, I choose to provide my answer using line breaks to avoid having the reader to scroll sideways...
New-ItemProperty `
-Path <value> `
-Name <value> `
-Value <value> `
-PropertyType <type>
But using the backtick is bad practice as it has low visibility and will break the code if you forgot about it when altering the amount of parameters or changes the order. Then splatting is a better choice.
One drawback with splatting though, is that empty values will be provided as $null parameters and will break some functions that doesn't properly handle $null values.
$registryPathshould be'HKLM:\SOFTWARE\WOW6432Node\OurC\Pricer\Application\ABCProxy'or'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\OurC\Pricer\Application\ABCProxy'and why do you wrap theNew-ItemPropertyandGet-ItemPropertylines inside curly braces (to make them script blocks) ??REG_DWORDmeans a 32-bit number, so you can omit the quotes around the values