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 @ Tuesday, August 19, 2008 7:29 PM

Comments on this entry:

No comments posted yet.

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 2 and 5 and type the answer here:
 
Twitter