Private/BuildQueryFromPSBound.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function BuildQueryFromPSBoundParameters([System.Collections.IDictionary]$psbp)
{
    $query = @{}
    foreach ($p in $psbp.GetEnumerator()) {
        #Need to ignore any switch parameters
        if ($p.Value -isnot [switch]) {
            #Get the key for the parameter, converting the first letter to
            #lowercase to match what REST API expects.
            $key = $p.key.substring(0,1).ToLower() + $p.key.substring(1)
            #Add to the query hashtable
            $query[$key] =  $p.Value
        }
    }

    return $query
}