Skip to content

Instantly share code, notes, and snippets.

@jdforsythe
Last active February 19, 2024 11:05
Show Gist options
  • Star 60 You must be signed in to star a gist
  • Fork 37 You must be signed in to fork a gist
  • Save jdforsythe/48a022ee22c8ec912b7e to your computer and use it in GitHub Desktop.
Save jdforsythe/48a022ee22c8ec912b7e to your computer and use it in GitHub Desktop.
Remote Desktop Auto Login Powershell Script
cmdkey /list | ForEach-Object{if($_ -like "*target=TERMSRV/*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}
echo "Connecting to 192.168.1.100"
$Server="192.168.1.100"
$User="Administrator"
$Password="AdminPassword"
cmdkey /generic:TERMSRV/$Server /user:$User /pass:$Password
mstsc /v:$Server
# https://technet.microsoft.com/library/hh847748.aspx
# Run PowerShell as Administrator
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nolog -command cmdkey /generic:TERMSRC/some_unc_path /user:username /pass:pa$$word; mstsc /v:some_unc_path
cmdkey /list | ForEach-Object{if($_ -like "*target=TERMSRV/*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}
echo "Connecting to somethingspecial.cloudapp.net"
$Server="somethingspecial.cloudapp.net"
$Port="49982"
$User="Administrator"
$Password="AdminPassword"
cmdkey /add:$Server /user:$User /pass:$Password
mstsc /v:$Server:$Port
@asgr8e
Copy link

asgr8e commented Apr 21, 2023

what if i want to start another ps script located in the remote server in which Iogged in with this script ? can anyone please support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment