functions/Get-PackageUpdateRule.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function Get-PackageUpdateRule {
    <#
    .SYNOPSIS
        Get rule(s) for checking and reporting on installed modules
 
    .DESCRIPTION
        This command get the existing custom rule(s) how modules are handled in reporting.
 
    .PARAMETER Id
        The Id as an identifier for the rule
 
    .PARAMETER ExcludeModuleFromChecking
        ModuleNames to exclude from update checking
 
    .PARAMETER IncludeModuleForChecking
        ModuleNames to include from update checking
        By default all modules are included.
 
        Default value is: "*"
 
    .PARAMETER IncludeDefaultRule
        Outputs the DefautRule from the setting object, in addition to the customrules
 
    .PARAMETER SettingObject
        Settings object parsed in from command Get-PackageUpdateSetting
        This is an optional parameter. By default it will use the default
        settings object from the module.
 
    .EXAMPLE
        PS C:\> Get-PackageUpdateRule
 
        Get all the existing custom rules
 
    .EXAMPLE
        PS C:\> Get-PackageUpdateRule -Id 1
 
        Get all the custom rule with Id 1
 
    #>

    [CmdletBinding(SupportsShouldProcess = $false, ConfirmImpact = 'Low', DefaultParameterSetName = "ShowAll")]
    [Alias('gpur')]
    [OutputType([PackageUpdate.ModuleRule])]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = "ById")]
        [ValidateRange(1, [int]::MaxValue)]
        [int[]]
        $Id,

        [Parameter(ParameterSetName = "ShowAll")]
        [Alias("Include", "IncludeModule")]
        [String]
        $IncludeModuleForChecking,

        [Parameter(ParameterSetName = "ShowAll")]
        [Alias("Exclude", "ExcludeModule")]
        [String]
        $ExcludeModuleFromChecking,

        [Parameter(ParameterSetName = "ShowAll")]
        [switch]
        $IncludeDefaultRule,

        [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [PackageUpdate.Configuration]
        $SettingObject
    )

    begin {
    }

    process {
        # If no setting object is piped in, get the current settings
        if (-not $SettingObject) { $SettingObject = Get-PackageUpdateSetting }

        $output = @()

        if ($Id) {
            $output += $SettingObject.CustomRule | Where-Object Id -in $Id | Sort-Object -Property Id
        } else {
            if ("ExcludeModuleFromChecking" -in $PSCmdlet.MyInvocation.BoundParameters.Keys) {
                $output += $SettingObject.CustomRule | Where-Object ExcludeModuleFromChecking -like $ExcludeModuleFromChecking | Sort-Object -Property Id
            } elseif ("IncludeModuleForChecking" -in $PSCmdlet.MyInvocation.BoundParameters.Keys) {
                $output += $SettingObject.CustomRule | Where-Object IncludeModuleForChecking -like $IncludeModuleForChecking | Sort-Object -Property Id
            } else {
                $output += $SettingObject.CustomRule | Sort-Object -Property Id
            }
        }

        if ($IncludeDefaultRule) {
            $output += $SettingObject.DefaultRule
        }

        $output
    }

    end {
    }
}