Public/Set-UWFBindByDriveLetter.ps1

Function Set-UWFBindByDriveLetter {
    <#
    .SYNOPSIS
        Sets the BindByDriveLetter property, which indicates if the Unified Write Filter (UWF) volume is bound to the physical volume by drive letter or volume name.
    .DESCRIPTION
        Sets the BindByDriveLetter property, which indicates if the Unified Write Filter (UWF) volume is bound to the physical volume by drive letter or volume name.
 
        Binding by volume name is considered more reliable than binding by drive letter, since drive letters can change for a volume if devices are added or removed.
    .PARAMETER BindByDriveLetter
        A Boolean value that indicates the type of binding to use. The BindByDriveLetter property is set to this value.
    .INPUTS
        None
    .OUTPUTS
        Returns an HRESULT value that indicates WMI status or a WMI error constant.
    .EXAMPLE
        Remove-UWFVolumeExclusion
    .LINK
        about_functions_advanced
    .LINK
        about_CommonParameters
    #>

    [CmdletBinding()]
    Param(
        [Parameter(
            Mandatory = $true
        )]
        [bool]$BindByDriveLetter
    )

    Begin {
    }
    Process {
        If (!$Script:UWFVolume) {
            $ExitCode = 424
            Throw "Unable to get handle to an instance of the UWF_Volume class"
        }
        $SetBindByDriveLetter = $Script:UWFVolume.SetBindByDriveLetter($BindByDriveLetter)
        $ExitCode = $SetBindByDriveLetter.ReturnValue
    }
    End {
        If ($Null -eq $ExitCode) {
            # 424 Failed Dependency
            $ExitCode = 424
        }
        If ($ExitCode -eq 0) {
            Write-Warning "Removing file and folder exclusion for $FileName on the next restart"
        }
        Return $("{0:x0}" -f $ExitCode)
    }
}