Public/Disable-UWF.ps1
Function Disable-UWF { <# .SYNOPSIS Disables Unified Write Filter (UWF) on the next restart. .DESCRIPTION Disables Unified Write Filter (UWF) on the next restart. You must use an administrator account to Disable UWF. .INPUTS None .OUTPUTS Returns an HRESULT value that indicates WMI status or a WMI error. .EXAMPLE Disable-UWF Returns 0 when successful. Otherwise, it returns error code. .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Medium" )] 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, "Disable Unified Write Filter")) { If (!$Script:UWF) { $ExitCode = 424 Throw "Unable to retrieve Unified Write Filter settings." } $Disable = $Script:UWF.Disable() $ExitCode = $Disable.ReturnValue } } End { If ($Null -eq $ExitCode) { # 424 Failed Dependency $ExitCode = 424 } If ($ExitCode -eq 0) { Write-Warning "Unified Write Filter will be disabled after the next system restart." } else { Write-Error $("Unknown Error: {0:x0}" -f $ExitCode) } Return $("{0:x0}" -f $ExitCode) } } |