Dec 032015
 
 December 3, 2015  Posted by at 10:08 am PowerShell  Add comments

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)

  One Response to “Saving RDP sessions with PoSh”

  1. Nice script thanks Iris. I just wanted to point out that the 4th line “$pdw” should be “$pwd”

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

What is 9 + 7 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)