Private/Get-HPSSecurityPolicyParameters.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
Function Get-HPSSecurityPolicyParameters {

    <#
        .SYNOPSIS
        Get current module path

        .DESCRIPTION
        Simple function to get module path with $ModulePath, and allow to makes it easy to test the project functions.

        .PARAMETER BoundParameters
        n/a

        .PARAMETER ParameterSetName
        n/a

        .PARAMETER ConfigName
        n/a

        .EXAMPLE
        Get-HPSModulePath

        .OUTPUTS
        System.String

        .LINK
        https://hardening.thomas-illiet.fr/Private/Get-HPSSecurityPolicyParameters/

        .LINK
        https://github.com/thomas-illiet/HardenedPS/blob/stable/Src/Private/Get-HPSSecurityPolicyParameters.ps1

        .NOTES
        - File Name : Get-HPSSecurityPolicyParameters.ps1
        - Author : Thomas ILLIET
    #>


    [CmdletBinding( HelpUri = "https://hardening.thomas-illiet.fr/Private/Get-HPSSecurityPolicyParameters/" )]
    [OutputType( [System.Object] )]
    Param(
        [Parameter( Mandatory = $True )]
        [System.Object]
        $BoundParameters,

        [Parameter( Mandatory = $True )]
        [System.Object]
        $ParameterSetName,

        [Parameter( Mandatory = $True )]
        [System.String]
        $ConfigName
    )

    begin {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
    }

    process {
        if( $ParameterSetName -eq 'Preset' ) {
            $Config = Get-HPSConfig -Name $ConfigName
            if( $Config.Preset.$Preset ) {
                $BoundParameters = $Config.preset.($Preset)
            } else {
                throw 'Preset not found'
            }
        }
        else {
            # Delete unnecessary variables
            $UnnecessaryVariables = @( 'Verbose', 'Debug', 'Detail', 'Cache' )
            foreach( $UnnecessaryVariable in $UnnecessaryVariables ){
                $BoundParameters.Remove($UnnecessaryVariable) | Out-Null
            }
        }

        $Parameters = @()
        foreach( $BoundParameter in $BoundParameters.GetEnumerator() ) {
            Write-Verbose $BoundParameter.Key
            $Parameters += [PSCustomObject]@{
                Name = $BoundParameter.Key
                Value = $BoundParameter.Value
            }
        }
        return $Parameters
    }

    end {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
    }

}