title: How to call a function with arguments with an array in Powershell?
body: <p>Consider this script in a file called <code>arrays.ps1</code></p>
  
  <pre><code>Function CallMe
  {
      param($arg1, $arg2)
      Write-Host "`$arg1 is $arg1"
      Write-Host "`$arg2 is $arg2"    
  }
  
  $args = "a","b"
  CallMe $args
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>PS C:\Users\Moomin\Documents&gt; .\arrays.ps1
  $arg1 is a b
  $arg2 is
  </code></pre>
  
  <p>If I modify it so the last line is </p>
  
  <p><code>CallMe $args.Split(" ")</code> </p>
  
  <p>I get the same output. How can I pass in an array to a function and split the array elements to arguments?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is closer to what I'm doing:</p>
  
  <pre><code>Function CallMe
  {
      param($y, $z)
      Write-Host "`$y is $y"
      Write-Host "`$z is $z"
  
  }
  
  Function DoSomething
  {
      param($x)
      Write-Host "This function only uses one arg: $x"
  }
  
  Function DoSomethingElse
  {
      Write-Host "This function does not take any arguments"   
  }
  
  
  $funcCalls = (
      ("DoSomething", "c"),
      ("CallMe", ("a","b")),
      ("DoSomethingElse", '')
      )
  
  
  foreach ($func in $funcCalls) {
      Write-Host "Executing function $($func[0]) with arguments `"$($func[1])`""
      &amp; $func[0] $func[1]
  }
  </code></pre>
  
  <p>If I run it this is the output:</p>
  
  <pre><code>PS C:\Users\Moomin\Documents&gt; .\arrays.ps1
  Executing function DoSomething with arguments "c"
  This function only uses one arg:
  Executing function CallMe with arguments "a b"
  $y is a b
  $z is
  Executing function DoSomethingElse with arguments ""
  This function does not take any arguments
  </code></pre>