Link to home
Create AccountLog in
Avatar of janhoedt
janhoedt

asked on

Powershell: auto-connect mstsc with credentials

Hi,

I'm trying to connect via powershell to an rdp session passing credentials but that does not work. RDP opens but credentials are not entered.
Pleaes advise

      
                  $Server = 'servername'
                  $User = "domain\usernamel"
                  $Password = "mypassword"
                  cmdkey /add:$Server /user:$User /pass:$Password
                  mstsc /v:$Server /admin /w:800 /h:600
Avatar of Hello There
Hello There

Why you don't create an RDP shortcut and save the credentials for the connection?

OR https://www.microsoft.com/en-us/download/details.aspx?id=44989

You can try this:
$Server="192.168.1.100"
$User="Administrator"
$Password="AdminPassword"
cmdkey /generic:"$Server" /user:"$user" /pass:"$password"
mstsc /v:"$Server"

Open in new window

Avatar of janhoedt

ASKER

It does not work on a domain joined computer. User and password are still asked.
Why you don't create an RDP shortcut and save the credentials for the connection?
Because it is a powershell script in which I don't want to mess with files.
This doesn't work: still prompted for password

$Server = 'myserver'
$User = "myuser"
$Password = "mypassword"
cmdkey /add:$Server /user:$User /pass:$Password
mstsc /v:$Server /w:1024 /h:768
Because it is a powershell script in which I don't want to mess with files.
Files?

Open Remote Desktop Connections -> type in the server name -> Connect -> type in the credentials -> tick "Remember my credentials" -> hit Enter.

Now your credentials are saved and every time you will need to RDP to the server, you won't be prompted for the username and password.
ASKER CERTIFIED SOLUTION
Avatar of janhoedt
janhoedt

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account