Fervent Coder

Coding Towards Utopia...by Rob Reynolds
posts - 278 , comments - 431 , trackbacks - 0

My Links


Rob Reynolds

Subscribe to Fervent Coder RSS
Subscribe to Fervent Coder by Email

About Me

I manage several open source projects. Need...
   ...package management for Windows?
   ...automated builds?
   ...database change management (migrations)?
   ...your application to check email?
   ...a monitoring utility?

I also write for

Like what you are reading? Want to buy me a cup of coffee?
PayPal - The safer, easier way to pay online!


Post Categories

Image Galleries


Calling PowerShell Functions with Parameters

This threw me for a loop today. You can't call a PowerShell function with commas "," or parentheses "()" and have it believe it goes to both parameters.  Try running the following and see what your output is on every line call to "foo."

function foo([string]$a, [string]$b)
   Write-Host "a:", $a, " b:", $b

foo("A", "B")
foo "A", "B"
foo "A" "B"
foo("A", "B") "C"

rm function:/foo

You may find you get different results than you may first expect. I did.

Reference: http://weblogs.asp.net/soever/archive/2006/11/29/powershell-calling-a-function-with-parameters.aspx

Print | posted on Tuesday, August 19, 2008 7:29 PM | Filed Under [ Code ApplicationsToysOther ]



# re: Calling PowerShell Functions with Parameters

OMG seriously this shouldn't have been so difficult to figure out. Thanks for the Post.

I have found this works also (v1):


foo $a ($a+$a)
>a:1 b:2
5/15/2009 7:25 PM | Joe
Comments have been closed on this topic.

Powered by: