Public/Reset-UWFSettings.ps1

Function Reset-UWFSettings {
    <#
    .SYNOPSIS
        Restores UWF settings to the original configuration settings.
    .DESCRIPTION
        Restores UWF settings to the original configuration settings.
 
        You must use an administrator account to reset UWF settings.
 
        The original configuration settings are captured the first time that you enable UWF after you add UWF to your device by using Turn Windows features on or off. You can change the original configuration settings by using Turn Windows features on or off to remove and then add UWF, and then modifying the configuration to the desired state before you enable UWF.
 
        If you added UWF to your device by using SMI settings in an unattend.xml file, the original configuration settings are captured when Windows 10 Enterpriseis installed on your device.
    .INPUTS
        None
    .OUTPUTS
        Returns an HRESULT value that indicates WMI status or a WMI error.
    .EXAMPLE
        Rest-UWFSettings
    .LINK
        about_functions_advanced
    .LINK
        about_CommonParameters
    #>

    [CmdletBinding(
        SupportsShouldProcess = $true
    )]
    Param()

    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($env:COMPUTERNAME, "Restore UWF settings")) {
            If (!$Script:UWF) {
                $ExitCode = 424
                Throw "Unable to retrieve Unified Write Filter settings."
            }
            $ResetSettings = $Script:UWF.ResetSettings()
            $ExitCode = $ResetSettings.ReturnValue
        }
    }

    End {
        If ($Null -eq $ExitCode) {
            # 424 Failed Dependency
            $ExitCode = 424
        }
        If ($ExitCode -eq 0) {
            Write-Output "Unified Write Filter have been reset."
        } Else {
            Write-Error $("Unknown Error: {0:x0}" -f $ExitCode)
        }
        Return $ExitCode
    }
}