Write Registry

From psadt | Evergreen Application Management
Jump to navigation Jump to search

About

Powershell.png

Powershell function to write to the Registry.


Function

#region Function
Function WriteReg
    {
	Param (
		[string]$Path,
		[string]$Name,
		[string]$Value,
		[Parameter(Mandatory=$false)]
		[ValidateSet('Binary','DWord','ExpandString','MultiString','None','QWord','String','Unknown')]
		[Microsoft.Win32.RegistryValueKind]$Type
		)
	If (!(Test-Path $Path))
		{New-Item -ItemType Directory $Path -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null}
	If (Test-Path $Path)
		{
		If ($Type)
			{New-ItemProperty -Path $Path -Name $Name -Value $Value -Type $Type -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null}
		Else
			{New-ItemProperty -Path $Path -Name $Name -Value $Value -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null}
		}
    }
#endregion