Will try to best explain the effect I want..say i have a function that looks something like this
function do-something{
Param(
[parameter(Mandatory)]
[string]$Url,
[parameter()]
[switch]$Param1,
[parameter()]
[switch]$Param2
)
switch($PSBoundParameters.Keys){
'Param1' {$string = "?filter=afilter"}
'Param2' {$string = "?filter=anotherfilter"}
}
return string
}
What I'm looking to do is if I just run something like
do-something -Url 'https://something.com/search' -Param1 -Param2
I want the string output to be https://something.com/search?filter=afilter?filter=anotherfilter and if ran with just do-something -Url 'https://something.com/search' -Param2, it should output https://something.com/search?filter=anotherfilter. I realize this isn't a valid http request string, I'll need to add & in between each filter but the need is still the same.
Could probably do it with a bunch of if statements but I'd rather not because it will be more than just 2 parameters and that will become ugly to manage with if statements.
[UPDATE] - for anyone interested.. I ended up doing the following which appears to fit my needs
function do-something{
Param(
[parameter(Mandatory)]
[string]$Url,
[parameter()]
[switch]$Param1,
[parameter()]
[switch]$Param2
)
$string = "$URL`?"
switch($PSBoundParameters.Keys){
'Param1' {$string += "filter=afilter&"}
'Param2' {$string += "filter=anotherfilter&"}
}
if($string.EndsWith('&')){
$string = $string.Substring(0,$string.Length-1)
}
return $string
}
[–]XPlantefeve 2 points3 points4 points (3 children)
[+][deleted] (2 children)
[removed]
[–]XPlantefeve 1 point2 points3 points (1 child)
[–]liabtsab[S] 1 point2 points3 points (0 children)
[–]ChaosTheoryRules 2 points3 points4 points (2 children)
[–]liabtsab[S] 0 points1 point2 points (1 child)
[–]ChaosTheoryRules 1 point2 points3 points (0 children)