Iris Classon
Iris Classon - In Love with Code

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

Leave a comment below, or by email.
Chris
12/18/2015 8:04:31 AM
Nice script thanks Iris. I just wanted to point out that the 4th line "$pdw" should be "$pwd" 


Last modified on 2015-12-03

comments powered by Disqus