New-Object : Cannot find an overload for "PSCredential" and the argument count: "2"

In situation like this, you may want to check your parameter type. In this particular example, the input parameter was declared to be a String. However, the result from ConvertTo-SecureString returns a SecureString.

The error message is a little misleading in this situation. The problem isn't because there is no constructor with 2 arguments but because $userPassword was declared to be a String but later was changed to SecureString.

[string][ValidateNotNullOrEmpty()] $userPassword = "myPassword",

$userPassword = ConvertTo-SecureString -String $userPassword -AsPlainText -Force
$userCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "myUserName", $userPassword