Public/Get-MSPBackupFilterList.ps1

Function Get-MSPBackupFilterList {
    <#
        .SYNOPSIS
            List FileSystem datasource filters. Produces a list with one filter mask per line.
        .DESCRIPTION
            List FileSystem datasource filters. Produces a list with one filter mask per line.
        .INPUTS
            None
        .OUTPUTS
            None
        .EXAMPLE
            Get-MSPBackupFilterList
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
    #>

    [CmdletBinding()]
    [OutputType('System.String')]
    Param()
    Begin {
        Write-Verbose ('{0}:: Function started' -f $MyInvocation.MyCommand)
        $stdOutTempFile = [System.IO.Path]::GetTempFileName()
        $stdErrTempFile = [System.IO.Path]::GetTempFileName()

        $ArgArray = @(
            "-machine-readable",
            "control.filter.list"
        )
    }
    Process {
        $StartProcessParams = @{
            FilePath               = $Script:CmdPath
            ArgumentList           = $ArgArray
            Wait                   = $true
            NoNewWindow            = $true
            PassThru               = $true
            RedirectStandardOutput = $stdOutTempFile
            RedirectStandardError  = $stdErrTempFile
            ErrorAction            = "SilentlyContinue"
        }
        $StartExe = Start-Process @StartProcessParams
        $ClientToolExitCode = $StartExe.ExitCode
        $ClientToolStandardOutput = Get-Content -Path $stdOutTempFile | Out-String
        $ClientToolStandardOutput = $ClientToolStandardOutput.Trim()
        $ClientToolStandardError = Get-Content -Path $stdErrTempFile | Out-String
        $ClientToolStandardError = $ClientToolStandardError.Trim()

        If ($stdOutTempFile -or $stdErrTempFile) {
            Remove-Item @RemoveItemParams
        }
        $ArgArray | Out-Null
        $ClientToolExitCode | Out-Null
        If ($null -ne $ClientToolStandardError) {
            $Output = $ClientToolStandardError
        } Else {
            $Output = $ClientToolStandardOutput
        }
    }
    End {
        Write-Verbose ('{0}:: Function ended' -f $MyInvocation.MyCommand)
        Return $Output
    }
}