-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-QueryString.ps1
More file actions
60 lines (57 loc) · 2.18 KB
/
Add-QueryString.ps1
File metadata and controls
60 lines (57 loc) · 2.18 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function Add-QueryString {
[CmdletBinding(DefaultParameterSetName = "KeyValue")]
[OutputType([System.Collections.IDictionary])]
param(
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[System.Collections.IDictionary]
$InputObject,
[parameter(Mandatory = $true, Position = 1, ParameterSetName = "KeyValue")]
[AllowNull()]
[AllowEmptyString()]
[Alias("Name")]
[string]
$Key,
[parameter(Mandatory = $true, Position = 2, ParameterSetName = "KeyValue")]
[AllowNull()]
[AllowEmptyString()]
[AllowEmptyCollection()]
[string[]]
$Value,
[parameter(Mandatory = $true, Position = 1, ParameterSetName = "Values")]
[System.Collections.IDictionary]
$Values
)
process {
switch ($PSCmdlet.ParameterSetName) {
"KeyValue" {
#Write-Host "Add-QueryString: '$Key'='$Value'"
$list = [System.Collections.ArrayList]::new()
foreach ($i in (ToString $InputObject[$key])) {
#Write-Host "InputObject: list.Add($i)"
$null = $list.Add($i)
}
foreach ($i in (ToString $Value)) {
#Write-Host "InputObject: list.Add($i)"
$null = $list.Add($i)
}
$InputObject[$Key] = $list
}
"Values" {
foreach ($kv in $Values.GetEnumerator()) {
$keys = ToString $kv.Key
if (IsEmpty $keys) {
$keys = [string]::Empty
}
foreach ($key in $keys) {
$list = ToString $kv.Value
if (IsEmpty $list) {
$list = [string]::Empty
}
$InputObject = $InputObject | Add-QueryString -Key $key -Value $list
}
}
}
}
$PSCmdlet.WriteObject($InputObject, $false)
}
}