ArgumentsProcessing/HandleJson.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
function HandleJson()
{
    [OutputType('System.Collections.Hashtable')]
    [CmdletBinding()]
    param(
        [Parameter()]
        [Switch] $NoEnumerate,

        [Parameter()]
        [Switch] $AsHashtable
    )

    $additionalArguments = @{}

    if ($NoEnumerate.IsPresent)
    {
        $additionalArguments.Add("NoEnumerate", $true)
    }

    if ($AsHashtable.IsPresent)
    {
        if ($PSVersionTable.PSVersion -ge [System.Management.Automation.SemanticVersion]"6.0.0")
        {
            $additionalArguments.Add("AsHashtable", $true)
        }
        else
        {
            throw "-AsHashtable can only be used on PowerShell 6.0 or newer"
        }
    }

    $additionalArguments
}