Private/WriteStream.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Function WriteStream {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline=$true)]
        [Object]$IndividualJob
    )
    Begin {
        $Streams = "Verbose","Warning","Error","Output"
    }

    Process {
        ForEach ($Stream in $Streams)
        {
            If (($IndividualJob.$Stream.Count -gt 0) -AND (-NOT ($Null -eq $IndividualJob.$Stream)))
            {
                Switch ($Stream) {
                    "Verbose" { $IndividualJob | Select -ExpandProperty Verbose | ForEach { Write-Verbose $_ } }
                    "Warning" { $IndividualJob | Select -ExpandProperty Warning | ForEach { Write-Warning $_ } }
                    "Error"   { $IndividualJob.Error.Exception | Select -ExpandProperty Message | ForEach { Write-Error $_ } }
                    "Output"  { $IndividualJob | Select -ExpandProperty Output }
                }
            }

        }
    }
}