Public/Get-UWFOverlayFiles.ps1

Function Get-UWFOverlayFiles {
    <#
    .SYNOPSIS
        Returns a list of files of a volume that were cached in the Unified Write Filter (UWF) overlay.
    .DESCRIPTION
        Returns a list of files of a volume that were cached in the Unified Write Filter (UWF) overlay.
 
        You must use an administrator account to access this method.
 
        The GetOverlayFiles method is intended to be used as a diagnostic tool.
 
        Do not base decisions about what to commit based on this method’s output.
 
        You should be aware of the following limitations:
 
        This method is only supported on the NTFS file system.
        This method requires a significant amount of free system memory to succeed (in a linear relationship to overlay usage). The method call fails when there is insufficient memory available to complete the call.
        This method requires significant time to complete (in an exponential relationship to overlay usage).
        This method may show files that are affected by seemingly unrelated operations to both registry and file exclusions and commits.
        You should also be aware of the following items when you use the GetOverlayFiles method:
 
        Files that were committed with the uwfmgr.exe file commit command are also contained in the overlay files list.
        Excluded files may be contained in the overlay files list.
        Files that are smaller than the cluster size (for example, 4 KB in most cases) will not be listed even if they are cached in overlay.
        Changes and deletions in excluded directories, excluded files, or excluded registry items add to overlay usage.
        File and registry commits add to overlay usage.
    .PARAMETER Volume
        A string that specifies the drive letter or volume name.
    .INPUTS
        None
    .OUTPUTS
        Returns an HRESULT value that indicates WMI status or a WMI error.
    .EXAMPLE
        Get-UWFOverlayFiles -Volume C:
    .LINK
        about_functions_advanced
    .LINK
        about_CommonParameters
    #>

    [CmdletBinding()]
    Param(
        [Parameter(
            Mandatory = $true,
            HelpMessage = "A string that specifies the drive letter or volume name."
        )]
        [String]$Volume
    )

    Begin { }

    Process {
        If (!$Script:UWFOverlay) {
            Throw "Unable to get handle to an instance of the UWF_Overlay class"
        }
        $OverlayFiles = $Script:UWFOverlay.GetOverlayFiles($Volume)
        $ExitCode = $OverlayFiles.ReturnValue
    }

    End {
        If ($Null -eq $ExitCode) {
            # 424 Failed Dependency
            $ExitCode = 424
        }
        If ($ExitCode -eq 0) {
            Return $OverlayFiles
        } Else {
            Return $("{0:x0}" -f $ExitCode)
        }
    }
}