code_junkie

How to expand a PowerShell array when passing it to a function

Nov 13th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. function inner
  2. {
  3. foreach( $arg in $args )
  4. {
  5. # do some stuff
  6. }
  7. }
  8.  
  9. function outer
  10. {
  11. inner --flag $args
  12. }
  13.  
  14. inner foo bar baz
  15.  
  16. outer wibble wobble wubble
  17.  
  18. inner --flag wibble wobble wubble
  19.  
  20. inner --flag [string]::Join(" ", $args)
  21.  
  22. function outer
  23. {
  24. invoke-expression "inner --flag $($args -join ' ')"
  25. }
Add Comment
Please, Sign In to add comment