Private/Get-PASParameter.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
100
101
102
103
104
105
function Get-PASParameter {
    <#
.SYNOPSIS
Removes defined parameter values from a passed $PSBoundParameters object

.DESCRIPTION
When passed a $PSBoundParameters hashtable, this function removes standard parameters
(like Verbose/Confirm etc) and returns the passed object with only the non-standard
parameters left in place.
This enables the returned object to be used to create the required JSON object to pass
to the CyberArk REST API.

.PARAMETER Parameters
This is the input object from which to remove the default set of parameters.
It is intended to accept the $PSBoundParameters object from another function.

.PARAMETER ParametersToRemove
Accepts an array of any additional parameter keys which should be removed from the passed input
object. Specifying additional parameter names/keys here means that the default value assigned
to the BaseParameters parameter will remain unchanged.

.PARAMETER BaseParameters
This is the default list of parameter names/keys which will be removed from the passed object.
Contains all standard parameters associated with PowerShell advanced functions, as well as
additional parameter names related to the CyberArk REST API but which are never included in a
JSON object sent to the API (URL for instance).
For normal operation, there is no need to pass anything for the BaseParameters parameter.
The default value should be used.

.EXAMPLE
$PSBoundParameters | Get-PASParameter

.EXAMPLE
Get-PASParameter -Parameters $PSBoundParameters -ParametersToRemove param1,param2

.INPUTS
$PSBoundParameters object

.OUTPUTS
Hashtable/$PSBoundParameters object, with defined parameters removed.
#>

    [CmdletBinding()]
    [OutputType('System.Collections.Hashtable')]
    param(
        [parameter(
            Position = 0,
            Mandatory = $true,
            ValueFromPipeline = $true)]
        [Hashtable]$Parameters,

        [parameter(
            Mandatory = $false)]
        [array]$ParametersToRemove = @(),

        [parameter(
            Mandatory = $false)]
        [array]$BaseParameters = @("Debug",
            "ErrorAction",
            "ErrorVariable",
            "OutVariable",
            "OutBuffer",
            "PipelineVariable",
            "Verbose",
            "WarningAction",
            "WarningVariable",
            "WhatIf",
            "Confirm",
            "SessionVariable",
            "InformationAction",
            "InformationVariable",
            "UseTransaction",
            "UseClassicAPI")
    )

    BEGIN {



    }#begin

    PROCESS {

        #Combine base parameters and any additional parameters to remove
        ($BaseParameters + $ParametersToRemove) |

        ForEach-Object {

            If ($Parameters.Contains($_)) {

                #remove specified parameters from passed values
                $Parameters.Remove($_)

            }

        }

    }#process

    END {

        #Return Object
        $Parameters

    }#end
}