Reputation: 13
My code:
try {
if(!(Test-Path -Path $registryPath -Value $Name)) {
New-ItemProperty -Name test -Path HKLM:\Software\WOW6432Node\Mozilla -PropertyType DWord -Value 2
}
}
catch {
Set-ItemProperty -Path $registryPath -Name $Name -Value $value
}
My Problem: the result comes out as string.
I have tried changing -PropertyType
to -Type
.
I have tried changing the capitilation of the word DWord
.
Any help would be greatly appreciated.
Upvotes: 1
Views: 8258
Reputation: 11
When using Set-ItemProperty to set a DWord type entry I have seen errors such as:
Set-ItemProperty : A parameter cannot be found that matches parameter name 'Type'.
Apparently older versions of Powershell/Set-ItemProperty did not include a Type parameter. In such cases the following syntax can work in its stead and this certainly worked in my case where the type param was not found:
[Microsoft.Win32.Registry]::SetValue("HKLM:\Software\WOW6432Node\Mozilla","test",2,[Microsoft.Win32.RegistryValueKind]::DWord)
Upvotes: 1
Reputation: 61253
As the docs say: You also use Set-ItemProperty to create and change registry values and data. For example, you can add a new registry entry to a key and establish or change its value.
With Set-ItemProperty it is also possible to change the type of registry entry from say a REG_SZ (string) value to DWord, so basically all you need is:
$registryPath = 'HKLM:\Software\WOW6432Node\Mozilla'
$propName = 'test'
Set-ItemProperty -Path $registryPath -Name $propName -Value 2 -Type DWord
Of course, if you do not have permissions to create or alter something in the HKEY_LOCAL_MACHINE registry path, you will rceive an error.
Upvotes: 1