Skip to content

Instantly share code, notes, and snippets.

@Sh1n0g1
Created March 23, 2017 03:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sh1n0g1/c08f2b0ea8ea5243fe9075b2e00b4fb4 to your computer and use it in GitHub Desktop.
Save Sh1n0g1/c08f2b0ea8ea5243fe9075b2e00b4fb4 to your computer and use it in GitHub Desktop.
Write Registry Value (and Create key if needed)
<#
.EXAMPLE
Write-RegistryValue -Path "HKCU:\Software\Sysinternals\Strings" -Name "EulaAccepted
#>
function Write-RegistryValue{
param (
[parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Path,
[parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Name,
[parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Value
)
Try{
If (!(Test-Path $Path)){
New-Item -Path (Split-Path $Path) -Name (Split-Path $Path -Leaf) -Force | Out-Null
}
Set-ItemProperty $Path -Name $Name -Value $Value
Return $True
}Catch{
Return $False
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment