4
votes
PS C:\Windows\system32> $creds = Get-Credential

cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters: Credential

PS C:\Windows\system32> $ses = New-PSSession -ComputerName WIN-O4VC136J0E2 -Credential $creds

New-PSSession : [WIN-O4VC136J0E2] Connecting to remote server WIN-O4VC136J0E2 failed with the following error message : The user name or password is incorrect. For more information, see the about_Remote_Troubleshooting Help topic. At line:1 char:8 + $ses = New-PSSession -ComputerName WIN-O4VC136J0E2 -Credential $creds + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin gTransportException + FullyQualifiedErrorId : LogonFailure,PSSessionOpenFailed

The credentials I used are the same ones I used to login manually. Is there something else I am doing wrong? I've tried several different ways and never can seem to login.

1
So the output of both these commands $cred.username and $cred.GetNetworkCredential().Password is what you would expect based on what you typed in yes? Is this a domain environment? Are you putting the domain in your login credentials?Matt
This is not a domain machine. This one is a local one. The username and password come out correct(well I am not sure out to get it out but I know I enter it correct). I am using Administrator for the usernameJason
I am not sure out to get it out The code I showed you would output the username and password on screen just so you could confirmMatt

1 Answers

0
votes

Try the following, works very nicely with either a domain account or local account:

# Enter your pass and stores it securely:
$SecureString = Read-Host -AsSecureString 'Enter your password ' | ConvertFrom-SecureString | ConvertTo-SecureString
# Users you password securly
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "MyLoCalMachine\MyUserID",$SecureString
# Sets yous credentials to be used
$RemoteConn = New-PSSession -ComputerName $ts -Credential $MySecureCreds -Authentication default