Color.psm1

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
. "$PSScriptRoot\config\Default.ps1"

. "$PSScriptRoot\util\Path.ps1"
. "$PSScriptRoot\util\String.ps1"

. "$PSScriptRoot\helpers\File.ps1"
. "$PSScriptRoot\helpers\MatchInfo.ps1"
. "$PSScriptRoot\helpers\Service.ps1"

$Script:showHeader = $true;

function Out-Default {
    [CmdletBinding(HelpUri = 'http://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability = 'None')]
    param(
        [switch] ${Transcript},
        [Parameter(Position = 0, ValueFromPipeline = $true)][PSObject] ${InputObject}
    )

    begin {
        try {
            $outBuffer = $null

            if ($PSBoundParameters.TryGetValue('OutBuffer', [ref] $outBuffer)) {
                $PSBoundParameters['OutBuffer'] = 1;
            }

            $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Out-Default', [System.Management.Automation.CommandTypes]::Cmdlet);
            $scriptCmd = {& $wrappedCmd @PSBoundParameters }

            $steppablePipeline = $scriptCmd.GetSteppablePipeline();
            $steppablePipeline.Begin($PSCmdlet);
        } catch {
            throw
        }
    }
    
    process {
        try {
            if (($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo])) {
                Write-File $_;
            } elseif ($_ -is [System.ServiceProcess.ServiceController]) {
                Write-Service $_;
            } elseif ($_ -is [Microsoft.Powershell.Commands.MatchInfo]) {
                Write-MatchInfo $_;
            } else {
                $steppablePipeline.Process($_);
            }
        } catch {
            throw
        }
    }

    end {
        try {
            $Script:showHeader = $true;
            $steppablePipeline.End();
        } catch {
            throw
        }
    }
}

Export-ModuleMember -Function Out-Default;