Functions/registry.ps1
function Set-RegistryValue( [Parameter(Mandatory = $true, Position = 0)] [ValidateNotNullOrEmpty()] [string]$regKeyPath, [Parameter(Mandatory = $true, Position = 1)] [ValidateNotNullOrEmpty()] [string]$regValueName) { $result = Get-RegistryValue $regKeyPath $regValueName if ($result -eq $null) { Write-Host "Creating Environment Key '${regValueName}' value '${regValue}'" Set-ItemProperty -Path HKCU:\Environment -Name ${regValueName} -Value $regValue } else { Write-Host "Environment Key '${regValueName}' already exists with value '${result}'" } } # Gets the specified registry value or $null if it is missing function Get-RegistryValue( [Parameter(Mandatory = $true, Position = 0)] [ValidateNotNullOrEmpty()] [string] $path, [Parameter(Mandatory = $true, Position = 1)] [ValidateNotNullOrEmpty()] [string] $name) { $key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue if ($key) { $key.GetValue($name, $null) } } |