Public/Set-UWFRegistryValue.ps1
Function Set-UWFRegistryValue { <# .SYNOPSIS Commits changes to the specified registry key and value. .DESCRIPTION Commits changes to the specified registry key and value. This method will commit only the value specified by ValueName under RegistryKey if ValueName is specified. You must use an administrator account to change any properties or call any methods that change the configuration settings. .PARAMETER RegistryKey A string that contains the full path of the registry key to be committed. .PARAMETER ValueName A string that contains the name of the value to be committed. .INPUTS System.String .OUTPUTS Returns an HRESULT value that indicates WMI status or a WMI error. .EXAMPLE Set-RegistryValue .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Medium" )] Param( [Parameter( Mandatory = $true, HelpMessage = "A string that contains the full path of the registry key to be committed." )] [String]$RegistryKey, [String]$ValueName ) Begin { If (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference') } If (-not $PSBoundParameters.ContainsKey('WhatIf')) { $WhatIfPreference = $PSCmdlet.SessionState.PSVariable.GetValue('WhatIfPreference') } If (-not $PSBoundParameters.ContainsKey('Confirm')) { $ConfirmPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ConfirmPreference') } If (-not $PSBoundParameters.ContainsKey('ErrorAction')) { $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference') } } Process { If ($PSCmdlet.ShouldProcess("RegistryKey: $RegistryKey, ValueName $ValueName", "Commit to registry")) { If (!$Script:UWFRegistryFilter) { $ExitCode = 424 Throw "Unable to get handle to an instance of the UWF_RegistryFilter class" } $CommitRegistry = $Script:UWFRegistryFilter.CommitRegistry($RegistryKey, $ValueName) $ExitCode = $CommitRegistry.ReturnValue } } End { If ($Null -eq $ExitCode) { # 424 Failed Dependency $ExitCode = 424 } If ($ExitCode -eq 0) { Write-Output "$RegistryKey has been added to exclusion list" } Return $("{0:x0}" -f $ExitCode) } } |