internal/functions/validate/Validate-RequestApprovalSettings.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
function Validate-RequestApprovalSettings
{
    [CmdletBinding()]
    Param (
        [ValidateSet("NoApproval", "SingleStage", "Serial")]
        [string] $approvalMode,
        [bool] $isApprovalRequired,
        [bool] $isApprovalRequiredForExtension,
        [bool] $isRequestorJustificationRequired,        
        [object[]] $approvalStages,
        [System.Management.Automation.PSCmdlet]
        $Cmdlet = $PSCmdlet
    )
    
    begin
    {}
    process
    {
        if (Test-PSFFunctionInterrupt) { return }                

        $hashtable = @{}
        foreach ($property in ($PSBoundParameters.GetEnumerator() | Where-Object {$_.Key -ne "Cmdlet"})) {
            if ($script:validateFunctionMapping.ContainsKey($property.Key)) {
                if ($property.Value.GetType().Name -eq "Object[]") {
                    $validated = @()
                    foreach ($value in $property.Value) {
                        $dummy = $value | ConvertTo-PSFHashtable -Include $($script:validateFunctionMapping[$property.Key].Parameters.Keys)
                        $validated += & $script:validateFunctionMapping[$property.Key] @dummy -Cmdlet $Cmdlet
                    }                    
                }
                else {
                    $validated = $property.Value | ConvertTo-PSFHashtable -Include $($script:validateFunctionMapping[$property.Key].Parameters.Keys)
                    $validated = & $script:validateFunctionMapping[$property.Key] @validated -Cmdlet $Cmdlet
                }                
            }
            else {
                $validated = $property.Value
            }
            $hashtable[$property.Key] = $validated
        }
    }
    end
    {
        $hashtable
    }
}