# Function parameters not working

**URL:** <https://forums.powershell.org/t/function-parameters-not-working/3242>\
**Category:** PowerShell Help\
**Created:** [October 11, 2014, 1:24am UTC](https://forums.powershell.org/t/function-parameters-not-working/3242 "2014-10-11T01:24:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![albert-van-wyk](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@albert-van-wyk](https://forums.powershell.org/u/albert-van-wyk)\
**Post date:** [October 11, 2014, 1:24am UTC](https://forums.powershell.org/t/function-parameters-not-working/3242/1 "2014-10-11T01:24:47Z")

</div>

Sorry if this has been covered in the forum …

take the following function

Function test ($val1, $Val2)  
{  
Write-Host $Val1

}

If I call the function : test(“one”,“two”) , I get output of one two , and not One only , it would seem that parameter two does not get populated , but parameter 1 ($val1) receives both values …

what am I missing … ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 11, 2014, 1:28am UTC](https://forums.powershell.org/t/function-parameters-not-working/3242/2 "2014-10-11T01:28:53Z")

</div>

PowerShell functions are called with parameters / arguments separated by spaces, not commas. There are also not any parentheses around the parameter list in the function call.

(“one”, “two”) is actually an array which is bound to a single parameter, as you’ve seen. With your function definition as-is (with two optional parameters that can both be passed by either name or position), here are the legal ways you could call it:

```
# no parameters
test

# two parameters by name
test -Val1 "one" -Val2 "two"

# two parameters by position
test "one" "two"

# One parameter by name (either one)
test -Val1 "one"
test -Val2 "two"

# One parameter by position (Val1 only)
test "one"
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 11, 2014, 1:29am UTC](https://forums.powershell.org/t/function-parameters-not-working/3242/3 "2014-10-11T01:29:27Z")

</div>

Check out Get-Help about\_Command\_Syntax for all the gory details. 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:47pm UTC](https://forums.powershell.org/t/function-parameters-not-working/3242/4 "2024-05-16T20:47:23Z")

</div>

Closed on May 16, 2024, 8:47pm UTC


