Skip to content

ConvertTo-UriQueryString

SYNOPSIS

Converts a hashtable of parameters into a URL query string.

SYNTAX

ConvertTo-UriQueryString [-Query] <IDictionary> [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

Takes a hashtable or dictionary of query parameters (keys and values) and constructs a properly encoded query string (e.g. "key1=value1&key2=value2"). By default, all keys and values are URL-encoded per RFC3986 rules to ensure the query string is valid. If a value is an array, multiple entries for the same key are generated.

EXAMPLES

EXAMPLE 1

ConvertTo-UriQueryString -Query @{ foo = 'bar'; search = 'hello world'; ids = 1,2,3 }

Output:

foo=bar&search=hello%20world&ids=1&ids=2&ids=3

Converts the hashtable into a URL-encoded query string. Spaces are replaced with %20.

EXAMPLE 2

ConvertTo-UriQueryString -Query @{ q = 'PowerShell'; verbose = $true }

Output:

q=PowerShell&verbose=True

Converts the query parameters into a valid query string.

PARAMETERS

-Query

The hashtable (or IDictionary) containing parameter names and values. Each key becomes a parameter name. Values can be strings or other types convertible to string. If a value is an array or collection, each element in it will result in a separate instance of that parameter name in the output string.

Type: IDictionary
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.String

NOTES

https://psmodule.io/Uri/Functions/ConvertTo-UriQueryString