Public/Get-HPWFCacheUsage.ps1

Function Get-HPWFCacheUsage {
    <#
        .SYNOPSIS
            Returns the cache usage for a file or directory of files.
        .DESCRIPTION
            Returns the cache usage for a file or directory of files. The length of this operation may vary depending on the number of files queried
        .PARAMETER Path
            The path to check.
        .PARAMETER RecureSubDirectories
            Enable Recursive usage check.
        .INPUTS
            System.IO.FileInfo
        .OUTPUTS
            Returns 0 when successful. Otherwise, it returns an error code.
        .EXAMPLE
            Get-HPWFCacheUsage -Path C:\SomePath
 
            Returns cache usage for C:\SomePath
        .EXAMPLE
            Get-HPWFCacheUsage -Path C:\SomePath -RecurSubDirectories
 
            Returns cache usage for C:\SomePath and it's sub-directories
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
        .LINK
            http://h10032.www1.hp.com/ctg/Manual/c06173592
    #>

    [CmdletBinding()]
    [OutputType('HPWriteManager.Cache.Usage')]
    Param(
        [Parameter(Mandatory = $true)]
        [ValidateScript( {
                Test-Path -Path $_
            })]
        [System.IO.FileInfo]$Path,
        [Switch]$RecureSubDirectories
    )
    Begin {
        If (!$RecureSubDirectories) {
            $RecureSubDirectories = 0
        } Else {
            $RecureSubDirectories = 1
        }
    }
    Process {
        If ($null -ne $HpWF) {
            $Ret = $HpWF.QueryCacheUsage($Path, $RecureSubDirectories)
            If ($Ret.ReturnValue -gt 0) {
                Throw "Failed to query path $Path for cache usage. Error: $Ret.ReturnValue"
            } Else {
                foreach ($Item in $Ret.FileInformation) {
                    $HPWFCU = [PSCustomObject]@{
                        FileName        = $Item.FileName
                        FileSize        = $Item.FileSize
                        CacheSize       = $Item.CacheSize
                        OpenHandleCount = $Item.OpenHandleCount
                        ProcessName     = $Item.ProcessName
                        UserName        = $Item.UserName
                    }
                    $HPWFCU.PSObject.TypeNames.Insert(0, 'HPWriteManager.Cache.Usage')
                }
            }
        }
    }
    End {
        If ($HPWFCU) {
            Return $HPWFCU
        }
    }
}