Public/Set-UWFOverlayCriticalThreshold.ps1

Function Set-UWFOverlayCriticalThreshold {
    <#
    .SYNOPSIS
        Sets the critical threshold for monitoring the size of the Unified Write Filter (UWF) overlay.
    .DESCRIPTION
        Sets the critical threshold for monitoring the size of the Unified Write Filter (UWF) overlay.
 
        When the size of the overlay reaches or exceeds the size threshold value, UWF writes the following notification event to the event log.
 
        Message ID: UWF_OVERLAY_REACHED_CRITICAL_LEVEL
        Event code: 0x80010001L
        Message text: The UWF overlay size has reached CRITICAL level.
 
        The critical threshold must be higher than the warning threshold.
    .PARAMETER ThresholdSize
        An integer that represents the size, in megabytes, of the critical threshold level for the overlay. If size is 0 (zero), UWF does not raise critical threshold events.
    .INPUTS
        None
    .OUTPUTS
        Returns an HRESULT value that indicates WMI status or a WMI error.
    .EXAMPLE
        Set-UWFOverlayCriticalThreshold -ThresholdSize 768
 
        This will set the Overlay Critical Threshold to 768 MB. Note that the critcal threhold must be higher than the warning threshold
    .LINK
        about_functions_advanced
    .LINK
        about_CommonParameters
    .LINK
        Set-UWFOverlayWarningThreshold
    #>

    [CmdletBinding(
        SupportsShouldProcess = $true
    )]
    Param(
        [Parameter(
            Mandatory = $true,
            HelpMessage = "Critical threshold value"
        )]
        [Int]$ThresholdSize
    )

    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()) {
            If (!$Script:UWFOverlay) {
                $ExitCode = 424
                Throw "Unable to get handle to an instance of the UWF_Overlay class"
            }
            $Critical = $Script:UWFOverlay.SetCriticalThreshold($ThresholdSize)
            $ExitCode = $Critical.ReturnValue
        }
    }

    End {
        If ($Null -eq $ExitCode) {
            # 424 Failed Dependency
            $ExitCode = 424
        }
        If ($ExitCode -eq 0) {
            Write-Output "Overlay critical threshold has been set to $ThresholdSize MB"
        }
        Return $("{0:x0}" -f $ExitCode)
    }
}