1

I have a simple .ps1 file:

$Server="remotepc.company.net"
$User=".\login"
$Password="password"

cmdkey /generic:TERMSRV/$Server /user:$User /pass:$Password
mstsc /v:$Server /h:1080 /w:1920

And anyway it asks for a password.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lagoda Denis
  • 235
  • 5
  • 13

3 Answers3

1

In RDP, go to the option checked to always ask for credentials:

Launch RDP → Show options → *un-check Always ask for credentials.

It seems, even though you gave credentials correctly, this was still making RDP ask.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
1

The issue was in $User=".\login".

login is a local user name (not domain).

So to force it to work:

$User="localhost\login"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lagoda Denis
  • 235
  • 5
  • 13
0

You could try:

$Server="remotepc.company.net"
$User="localhost\login"
$Password="password"
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force

cmdkey /generic:$Server /user:$User /pass:$SecurePassword
mstsc /v:$Server /h:1080 /w:1920
Will Webb
  • 795
  • 6
  • 20