Search code examples
powershellpowershell-2.0powershell-3.0

Remote server login error


Hi I want to login into my remote server using power shell . I wrote code for this but I am getting error .

CODE

  $cred = get-credential - Prompts for username and password
  Enter-PSSession -ComputerName  servername -Credential $cred

ERROR

Get-Credential : A positional parameter cannot be found that accepts argument 'Prompts'.At C:\documents\Untitled8.ps1:1 char:9 + $cred = get-credential - Prompts for username and password + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-Credential], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetCredentialCommand

Enter-PSSession : Connecting to remote server XXXXX failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.At C:\documents\Untitled8.ps1:5 char:1 + Enter-PSSession -ComputerName servername -Credential $cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (servername:String) [Enter-PSSession], PSRemotingTransportException + FullyQualifiedErrorId : CreateRemoteRunspaceFailed

Any clue regarding this will help.... Get-Credential : A positional parameter cannot be found that accepts argument 'Prompts'

Anybody have any clue how to login into remote server in power shell using servername..any clue any link regarding this will be helpful


Solution

  • The problem is that there it can´t find a positional parameter, where "Prompts" is accepted. If you look at the help file for Get-credential you will see that the -Credential paramenter is positional, meaning you dont need to type it.

    Try with this

      $cred = get-credential -Message "Prompts for username and password"
      Enter-PSSession -ComputerName  servername -Credential $cred
    

    Some reading about positional parameters https://itknowledgeexchange.techtarget.com/powershell/positional-parameters/