Set-RegistryValue
Description:
Function sets a registry value, creating the path if it does not exist, and modifying the value if it already exists as well.
Language:
PowerShell
Usage Type:
Packaging Function
Script Source:
function Set-RegistryValue ($ValuePath, $ValueName, $ValueData) { ########################################################### # Set-RegistryValue # Function by: Sean Huggans # Function Date: 2018.08.14 ########################################################### # Function will set a registry value, creating the key path if it does not already exist. # Usage Example: Set-RegistryValue -ValuePath "Software\Tests\Test 3" -ValueName "Test Value 4" -ValueData "Test Data REVISED 2" if (($ValuePath -ne "") -and ($ValueName -ne "") -and ($ValueData -ne "")) { $RegistryObject = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME) $RegistryObject.CreateSubKey("$($ValuePath)") | Out-Null $RegistryKey = $RegistryObject.OpenSubKey("$($ValuePath)", $true) try { $RegistryKey.SetValue("$($ValueName)", "$($ValueData)", [Microsoft.Win32.RegistryValueKind]::String) | Out-Null Log-Action "Registry Add: $($ValuePath)\$($ValueName) ($($ValueData)): Success!" return $true } catch { Log-Action "Registry Add: $($ValuePath)\$($ValueName) ($($ValueData)): Error!" return $false } } else { Log-Action "Error: Set-RegistryValue was called with missing parameters!" return $false } }
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.