Public/Publish-UWFFile.ps1

Function Publish-UWFFile {
    <#
    .SYNOPSIS
        Commits changes from the overlay to the physical volume for a specified file on a volume protected by Unified Write Filter (UWF).
    .DESCRIPTION
        Commits changes from the overlay to the physical volume for a specified file on a volume protected by Unified Write Filter (UWF).
        The FileName must contain the name of a file that exists. The CommitFile method cannot commit a file that does not exist.
 
        You must use an administrator account to change any properties or call any methods that change the configuration settings.
    .PARAMETER FileName
        A string that contains the path of the file to commit on the overlay, but does not include the drive letter or volume name. For example, “\users\test.dat”.
    .INPUTS
        System.String
    .OUTPUTS
        Returns an HRESULT value that indicates WMI status or a WMI error constant.
    .EXAMPLE
        Publish-UWFFile -FileName "C:\Operator\file.txt"
    .LINK
        about_functions_advanced
    .LINK
        about_CommonParameters
    #>

    [CmdletBinding(
        SupportsShouldProcess = $true,
        ConfirmImpact = "Medium"
    )]
    Param(
        [Parameter(
            Mandatory = $true,
            HelpMessage = "A string that contains the path of the file to commit on the overlay, but does not include the drive letter or volume name."
        )]
        [string]$FileName
    )

    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:UWFVolume) {
                $ExitCode = 424
                Throw "Unable to get handle to an instance of the UWF_Volume class"
            }
            $CommitFile = $Script:UWFVolume.CommitFile($FileName)
            $ExitCode = $CommitFile.ReturnValue
        }
    }

    End {
        If ($Null -eq $ExitCode) {
            # 424 Failed Dependency
            $ExitCode = 424
        }
        If ($ExitCode -eq 0) {
            Write-Warning "Committing $FileName on the next restart"
        }
        Return $("{0:x0}" -f $ExitCode)
    }
}