none
Looping through all parameters in a function to concatenate all non-null parameters RRS feed

  • Question

  • I'm using PowerShell to grab information from a website, which I've been able to do successfully with Invoke-RestMethod.

    The website puts it's various options in the URL itself, such as http://www.contoso.com/?opt1=on&opt2=12345

    What I'd like to do is create a function to run the Invoke-RestMethod cmdlet, and have a parameter for each option available.  The Function would have a parameter for each option available to put in the URL, and then concatenate all the non-null parameters into the URi for the Invoke-RestMethod cmdlet.

    Is there an easy way to loop through all the parameters in the function to see which one's are in use, and concatenate them into the full URi without calling every parameter individually?

    Sunday, September 6, 2015 1:51 PM

Answers

  • $PSBoundParameters contains all parameters that actually have a value.

    \_(ツ)_/

    • Marked as answer by aydeisen Sunday, September 6, 2015 5:39 PM
    Sunday, September 6, 2015 3:17 PM