Private/Set-RegistryKey.ps1
function Set-RegistryKey { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $Path, [Parameter(Mandatory = $true)] [ValidateNotNull()] [AllowEmptyString()] [String] $Name, [String] $Value, [ValidateNotNullOrEmpty()] [String] $Type ) if (Test-RegistryKeyExists -Path $Path) { $ItemValue = (Get-RegistryKey -Path $Path).$Name if([string]::IsNullOrEmpty($ItemValue)) { New-RegistryValue -Path $Path -Name $Name -Value $Value -Type $Type } else { if($ItemValue -ne $Value) { Set-ItemProperty -Path "Registry::$Path" -Name $Name -Value $Value } } } } |