Writing to the Registry

by Nov 30, 2009

Adding or changing registry values is not always intuitive with PowerShell. Here is a function called Set-RegistryValue that will make your life easier:

function Set-RegistryValue($key, $name, $value, $type="String") {
if ((Test-Path $key) -eq $false) { md $key | Out-Null }
Set-ItemProperty $key $name $value -type $type
}
Set-RegistryValue HKCU:\Software\TestABC myValue Hello
Set-RegistryValue HKCU:\Software\TestABC myValue 12 Dword
Set-RegistryValue HKCU:\Software\TestABC myValue `
([Byte[]][Char[]]"Hello") Binary

Twitter This Tip! ReTweet this Tip!