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
Powershell

Avatar of undefined
Last Comment
janhoedt

8/22/2022 - Mon
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

janhoedt

ASKER
It does not work on a domain joined computer. User and password are still asked.
Hello There

Why you don't create an RDP shortcut and save the credentials for the connection?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
janhoedt

ASKER
Because it is a powershell script in which I don't want to mess with files.
janhoedt

ASKER
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
Hello There

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
janhoedt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.