You are not logged in.
Pages: 1
I'm trying to find a script which allows me to modify Keys / Values in the registry.
What I have in mind (for easy reading the complete Hive till valuename is referred to as [NAME]:
1) allows modification of any [NAME] Valuetype (DWORD / Boolean / ...) including the Hex-value ones
2) copies [NAME] to [NAME]_Original (only when [NAME]_Original does not exist --> so only the first time and will contain the Windows-default)
3) copies [NAME] to [NAME]_Previous (obveous, will always contain the previous value)
4) modify [NAME] to the provided value
Does anyone knows scripts (or other tool) allowing to do that in batch ?
Because I haven't PowerShell experience, and because we're talking about the registry I would like to minimize risks involved by trial-and-error
Thanks
Offline
This script ought to help you out a little.
$scriptName = 'Get-RegistryKey'
$installedScript = Get-InstalledScript -Name $scriptName -ErrorAction SilentlyContinue
if (!$installedScript) {
Install-Script -Name $scriptName -WarningAction Stop
$installedScript = Get-InstalledScript -Name $scriptName -ErrorAction Stop
}
. (Join-Path -Path $installedScript.InstalledLocation -ChildPath ($scriptName + '.ps1'))
function SafeRegistryValueSet {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[Alias('PSPath', 'KeyName')]
[string]
$Path,
[Parameter(Mandatory)]
[string]
[Alias('ValueName')]
$Name,
[Parameter(Mandatory)]
[Object]
$Data,
[Microsoft.Win32.RegistryValueKind]
$ValueKind = [Microsoft.Win32.RegistryValueKind]::Unknown
)
if ($regkey = Get-RegistryKey -Path $Path) {
if ($existingData = $regkey.GetValue($Name)) {
$regkey.SetValue($Name + '_Previous', $existingData, $ValueKind)
if (!$regkey.GetValueNames().Contains($Name + '_Original')) {
$regkey.SetValue($Name + '_Original', $existingData, $ValueKind)
}
}
$regkey.SetValue($Name, $Data, $ValueKind)
} else {
Write-Error "The registry key '$Path' could not be opened."
}
}
$entries = (
('HKCU:\test', 'foo', 1),
('HKCU:\test', 'bar', 2),
('HKCU:\test', 'baz', 3)
) | % {
@{
Path = $_[0]
Name = $_[1]
Data = $_[2]
}
}
foreach ($entry in $entries) {
SafeRegistryValueSet @entry
}
Offline
Pages: 1