-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertFrom-QueryString.ps1
More file actions
37 lines (37 loc) · 1.31 KB
/
ConvertFrom-QueryString.ps1
File metadata and controls
37 lines (37 loc) · 1.31 KB
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
function ConvertFrom-QueryString {
[CmdletBinding()]
[OutputType([System.Collections.IDictionary])]
param(
[parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[AllowNull()]
[AllowEmptyString()]
[string]
$InputObject
)
begin {
$t = New-QueryString
}
process {
if ([string]::IsNullOrEmpty($InputObject)) { return }
$InputObject = $InputObject -replace "^[^\?]*\?", ""
foreach ($kv in ($InputObject -split "&")) {
if ($kv -match "^([^=]*)(=(.*))?$") {
$key = [System.Net.WebUtility]::UrlDecode($Matches[1])
$value = [System.Net.WebUtility]::UrlDecode($Matches[3])
switch ($Matches.Count) {
2 {
#Write-Host "ConvertFrom-QueryString: ''='$key'"
$t = $t | Add-QueryString -Key ([string]::Empty) -Value $key
}
4 {
#Write-Host "ConvertFrom-QueryString: '$key'='$value'"
$t = $t | Add-QueryString -Key $key -Value $value
}
}
}
}
}
end {
$PSCmdlet.WriteObject($t, $false)
}
}