title: Powershell URI builder for a sys admin
body: <p>Forgive my ignorance - I am trying to write a powershell cmdlet which takes user input and builds a query uri to an API (one mandatory, 3 opts) - I have kind of got the general idea that I need to use hash tables for dictionary of query strings and parameters.</p>
  
  <p>I'm trying to build <code>$baseurl + $querystring + '=' + $parameter + '&amp;' + $querystring + '=' $value (if not null)</code></p>
  
  <p>e.g. <code>https://example.com/api?param1=value&amp;param2=value</code></p>
  
  <p>so far - and this is very rough, and completely not working:</p>
  
  <pre><code>            Function Get-commonURI{ #takes 4 params from user
                  [CmdletBinding()]
                  Param(
                      [Parameter(Mandatory=$true,
                                  ValueFromPipeline=$true,
                                  ValueFromPipelineByPropertyName=$true)]
  
                                  [String[]]$value1
  
                                  [Parameter(Mandatory=$false,
                                  ValueFromPipeline=$true,
                                  ValueFromPipelineByPropertyName=$true)]
  
                                  [String[]]$value2,
                                  [String[]]$value3,
                                  [String[]]$value4 
  
                  ) #end param 
              }
          #put the input into a paramter hash table with the query strings
  
          $Parameters = @{
              query = 'querysting1', 'querystring2', 'querystring3', 'querystring4'
              values = $value1,$value2.$value2, $value4
          }
  
          uri = https://example.com/api?
  
      $HttpValueCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
  
      foreach ($Item in $Parameters.GetEnumerator()) {
  #I want to append each query passed in on the cli
  
  foreach ($Value in $Item.Value) {
        $ParameterName = $Item.value
  
        $HttpValueCollection.Add($ParameterName, $Value)}
  
  $Request  = [System.UriBuilder]($Uri)
  $Request.Query = $HttpValueCollection.ToString()
  
  invoke-webrequest $Request.Uri
  
  }
  </code></pre>
  
  <p>I have something like that written but it's not working - am I even on the right track here? - I'm sure this has been done a million times but don't even know what to google - something tells me I shouldn't set up the hash table with variables. thanks for looking.</p>