Functions/Get-ScriptLogger.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
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
<#
    .SYNOPSIS
        Get the current script logger.
 
    .DESCRIPTION
        Returns an object with the current configuration of the script logger
        inside this PowerShell session.
 
    .INPUTS
        None.
 
    .OUTPUTS
        ScriptLogger.Configuration. Configuration of the script logger instance.
 
    .EXAMPLE
        PS C:\> Get-ScriptLogger
        Get all script loggers.
 
    .EXAMPLE
        PS C:\> Get-ScriptLogger -Name 'MyLogger'
        Get the custom script logger.
 
    .NOTES
        Author : Claudio Spizzi
        License : MIT License
 
    .LINK
        https://github.com/claudiospizzi/ScriptLogger
#>


function Get-ScriptLogger
{
    [CmdletBinding()]
    param
    (
        # The logger name filter.
        [Parameter(Mandatory = $false)]
        [System.String]
        $Name
    )

    $selectedLoggers = $Script:Loggers.Values

    if ($PSBoundParameters.ContainsKey('Name'))
    {
        $selectedLoggers = $selectedLoggers | Where-Object { $_.Name -like $Name }
    }

    Write-Output $selectedLoggers
}