Created
March 23, 2017 03:00
-
-
Save Sh1n0g1/c08f2b0ea8ea5243fe9075b2e00b4fb4 to your computer and use it in GitHub Desktop.
Write Registry Value (and Create key if needed)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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