TestFunction($Name, $Count)
Before I go any further, let's define TestFunction:
function TestFunction
($name,
$count)
{
Write-Output
"Name is '$name' and Count is '$count'"
}
function TestFunction
{
param($name, $count)
Write-Output
"Name is '$name' and Count is '$count'"
}
So now we have a function that takes two arguments. The first argument is name and the second argument is count. Here are the correct ways to call that function:
TestFunction $Name $Count
TestFunction -name $Name -count $Count
TestFunction -name "Kevin" -count
1
Now that we know the correct way to make that call and know what the function looks like, I can explain why our initial call fails to work. Because it is the equivalent to this call:
$Array = ($Name,$Count)
TestFunction -name $Array -count $null
So you were basically creating an array that contained your two variables and passing it in as an array to the first argument. You were also leaving the second argument as a null value. Now that you see it, it looks like a silly thing to do. No wonder things were not working as you expected.
No comments:
Post a Comment