Functions/Data/Convert-HashtableToQueryString.ps1
Function Convert-HashtableToQueryString { [cmdletbinding()] Param ( # Hashtable input [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [System.Collections.IDictionary] $hashtable, # Prepend the ? Mark [Parameter(Mandatory=$false)] [boolean] $eroteme = $true ) Process { # Split Hashtable into Queries $Queries = foreach ($key in $hashtable.keys){"$key=$($hashtable.$key | ConvertTo-URLEncoding)"} # Compose Queries into Querystring $QueryString = Switch ($eroteme) { $TRUE {"?"+"$($Queries -join '&')"} $FALSE {"$($Queries -join '&')"} } # Output QueryString $QueryString } } |