Command switches interpreted as positioned parameter

Hi

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

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:

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

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.

Hi

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

Regards