Saving RDP sessions with PoSh
I honestly can’t remember if I blogged this or not, but since I can’t find the blog post I will just assume that I didn’t. I thought I’d share a few lines of PowerShell for something rather handy. I seem to be constantly RDPing and since I mainly work and navigate from a shell it makes sense to have my sessions easily accessible that way. It’s rather straight forward to register a RDP connection in PowerShell:
$target = "111.111.11.11"
$user = "adm"
$computerNameOrDomain = "DESKTOP-1"
# $pdw = "the password"
$logon = "$computerNameOrDomain\$user"
cmdkey /generic:$target /user:$logon #/pass:$pwd
cmdkey /list
mstsc /v:$target
[Environment]::SetEnvironmentVariable("rdp1", "mstsc /v:$target", "Machine")
#Restart after this
# Run RDP session:
iex (gc Env:rdp1)
Comments
Chris
Last modified on 2015-12-03