title: Powershell: Passing parameters to function
body: <p>So I'm doing a bit of 'House Keepying' on my script and I've found one area than can be reduced/tidied.
  Take this GUI I've created:</p>
  
  <p><img src="https://i.stack.imgur.com/L6aqT.jpg" alt="enter image description here"></p>
  
  <p>Both menu bar <code>add_click</code> events to Restart HostnameA and HostnameB call seperate functions even though the code in both of the functions is pratically the same, the only difference is this variable for the hostname (see below).</p>
  
  <p>Code for button events.</p>
  
  <pre><code>$Restart_current_machine.Add_Click(
  {
  restart_current_machines
  })
  
  $Restart_target_machine.Add_Click(
  {
  restart_target_machines
  })
  
  # Function Blocks
  
  function restart_target_machines
  {
  restart-computer -computer $combobox1.text -force
  }
  
  function restart_current_machines
  {
  restart-computer -computer $combobox2.text -force
  }
  </code></pre>
  
  <p>My question is this: 
  is there a way I can use <code>Param()</code> (or something like that) to get rid of <code>function restart_current_machines</code>thereby only having one function to restart either of the machines?</p>
  
  <p>Something like?</p>
  
  <pre><code>$Restart_current_machine.Add_Click(
  {
  param($input = combobox1.text)
  $input | restart_current_machines
  })
  
  $Restart_target_machine.Add_Click(
  {
  param($input = combobox2.text)
  $input | restart_current_machines
  })
  
  # Only needing one function
  
  function restart_target_machines
  {
  restart-computer -computer $input -force
  }
  </code></pre>
  
  <p>I know that is in all probability wrong, but just to give you a better idea of what I'm trying to do.</p>