# Command switches interpreted as positioned parameter

**URL:** <https://forums.powershell.org/t/command-switches-interpreted-as-positioned-parameter/17475>\
**Category:** PowerShell Help\
**Created:** [September 3, 2021, 1:41pm UTC](https://forums.powershell.org/t/command-switches-interpreted-as-positioned-parameter/17475 "2021-09-03T13:41:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![norphf](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@norphf](https://forums.powershell.org/u/norphf)\
**Post date:** [September 3, 2021, 1:41pm UTC](https://forums.powershell.org/t/command-switches-interpreted-as-positioned-parameter/17475/1 "2021-09-03T13:41:10Z")

</div>

Hi

I have created the following psm1 script to have some standard custom functions easy at hand.  
This

```auto
function Connect-4twRemoteServer {
    [CmdletBinding()]
    param (
        # Enter the server you want to connect to
        [Parameter(Mandatory=$true)]
        [string[]]
        $4twServer,
        # Please specify credentials for the connection
        [Parameter(Mandatory=$false)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $4twCreds = [System.Management.Automation.PSCredential]::Empty,
        # Parameter help description
        [Parameter()]
        [switch]
        $GetCreds
    )
    
    begin {
        Write-Debug "Trying to connect to $4twServer"
        Write-Debug "With user $($4twCreds.UserName)"
        Write-Debug "In Begin section"
        if ($4twServer -eq "") {
            Write-Warning "You must specify a server to connect to."
            Break
        }
        if ($GetCreds){
            $4twCreds = Get-Credential
        }
    }
}

```

gives this debug output:

```auto
PS C:\Users\l> Connect-4twRemoteServer -4twServer "10.10.83.248" -Debug

PowerShell credential request
Enter your credentials.
Password for user 10.10.83.248: *

DEBUG: Trying to connect to -4twServer
DEBUG: With user 10.10.83.248
DEBUG: In Begin section

```

So the -4twServer (Which I didn’t type myself, but tap-completed) is suddenly treated as positional parameter 0 and the value it should have is parameter 1.

Please advice, what is wrong?

[EDIT] I have tested with Code and PS 5.1/7.1 and in a normal PS 7.1 console [/EDIT]

Regards Lars Mortensen

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [September 3, 2021, 3:19pm UTC](https://forums.powershell.org/t/command-switches-interpreted-as-positioned-parameter/17475/2 "2021-09-03T15:19:14Z")

</div>

I’m having trouble finding any official documentation to point you towards, but I am fairly certain that parameter names should not (cannot?) start with a number.

---

<div class="post-metadata">

**Author:** ![norphf](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@norphf](https://forums.powershell.org/u/norphf)\
**Post date:** [September 3, 2021, 3:37pm UTC](https://forums.powershell.org/t/command-switches-interpreted-as-positioned-parameter/17475/3 "2021-09-03T15:37:42Z")

</div>

Hi

I would have sworn I have tried that, but just tried again, and now it works.  
Thank you!

Regards

---

<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:21pm UTC](https://forums.powershell.org/t/command-switches-interpreted-as-positioned-parameter/17475/4 "2024-05-16T20:21:37Z")

</div>


