I shared with you how to create multiple .rdp files with Powershell, and now, I want to show you how to make your job even easier! I ran across this blog, and downloaded his RDP password Hash program. It got me thinking, I could make my job easier by saving the password in a hashed format in each RDP file that my Powershell script creates!
** Note: Please see my original post about this if you have questions of the files needed, and folder structure.
First, I modified the .CSV file, adding a new column “PASS” – in that column, add the hashed password created from remkoweijnen.nl’s password hash program [DOWNLOAD]
Then I modified my Powershell script, adding in the password to script, so it’s added to the .RDP file.
No more typing in passwords to connect to servers. Also, the nice thing is, if you have to change the password, just modify the hash file in the .CSV file, and re-run the Powershell script!
Here is the modified Powershell Script:
$List = Import-CSV RDPLIST.CSV $resolutions = ("Console","Cullscreen","Widescreen","Docked") ForEach($Entry in $List) { ForEach($resolution in $resolutions) { # Prepend the destination directory info for RDP files $Dir = "..\" + $resolution + "\" + $Entry.Directory # Create new folder New-Item -Path $Dir -ItemType Directory -Force # Build the file name $FileName = $Dir + "\" + $Entry.ServerName + ".RDP" # Remove the old file Remove-Item $FileName -Force # Begin building RDP file $temp = "`nfull address:s:" + $Entry.IP switch ($resolution) { "Console" { $temp += "`nscreen mode id:i:1" $temp += "`ndesktopwidth:i:1024" $temp += "`ndesktopheight:i:768" $temp += "`nusername:s:" + $Entry.USER $temp += "`npassword 51:b:" + $Entry.PASS $temp += "`nadministrative session:i:1" } "Fullscreen" { $temp += "`nscreen mode id:i:2" $temp += "`nusername:s:" + $Entry.USER $temp += "`npassword 51:b:" + $Entry.PASS } "Widescreen" { $temp += "`nscreen mode id:i:1" $temp += "`ndesktopwidth:i:1152" $temp += "`ndesktopheight:i:720" $temp += "`nusername:s:" + $Entry.USER $temp += "`npassword 51:b:" + $Entry.PASS } "Docked" { $temp += "`nscreen mode id:i:1" $temp += "`ndesktopwidth:i:1152" $temp += "`ndesktopheight:i:864" $temp += "`nusername:s:" + $Entry.USER $temp += "`npassword 51:b:" + $Entry.PASS } } $temp | out-file $FileName write-host $temp get-content template_bottom.txt >> $FileName } }
Related posts:
Microsoft DPM
MicrosoftExchange
Nerd with a .45
PowerShell
So, this post, combined with the latest post on Visio is quite an interesting convergence for me. I’ve been struggling recently with hyperlinking from a visio object directly to a RDP connection. The only way I’ve been able to swing it to host a web service, the sole purpose of which, is to return a RDP file. Hyperlinking from an object in visio to a RDP connection is a nice way to visually manage your infrastructure…. Any thoughts on this, other then something that requires I ship actual RDP connections with a visio file? Thanks
Hey Sundanceca!
I’m glad you liked the post! I do something similar that you are doing with Visio. To launch from visio, try creating the hyperlink to point to MSTSC.exe with aruments – like this file://mstsc.exe “c:\rdp\1024×768\computer.rdp”
See if that works. If not, let me know, and I’ll see if I can get something working for you!
thanks for the reply.
I wanted to avoid the mstsc option because that would require that I distribute the rdp files with visio file, something I wasn’t excited about.
I coded a asp.net app to take a server name param and return a rdp connection, but that requires that I host it…
Hi!
Thanks for your excellent work.
Have you figured out a way to get this to work with RDPv6?
I’d really appreciate a way to do this, even if it means adding entries to the registry.
Thanks in advance,
Panarchy
@ Panarchy – I have used this with RDPv6 without any issues.
Thanks Buddy !
I am struggling since 3 days to encrypt and decrypt the password.
You resolved my issue in 5 mins.
Once again thanks & great JOB
Just an FYI -
If you add a couple lines to your code, and use a command line version of the GUI tool you showed, it will be fully automatic. It prompts you to type your password, and injects the returned hash into all the files.
The command line version is called “cryptRDP5.exe” and can easily be found with a google search. Just put it in the same folder as the modified Powershell script below & run it.
Enjoy!
One last note: If you have WinXP machines, and Win7 machines, the RDP files won’t work on each other. I’ve found you need to re-run the script to re-hash on both OS’s to get the proper hash or it doesn’t work. (Originally I just copied the WinXP RDP files I generated to the Win7 machine, but they wouldn’t auto-login. After looking at the hashes as run on each machine, it generates different hash on different machines.)
$PW = read-host "type a your Login password here"
$hashPWCmd = ".\cryptRDP5.exe " + $PW
$PWHash = Invoke-Expression $hashPWCmd
Write-Host $PWHash
$List = Import-CSV RDPLIST.CSV
$resolutions = ("Fullscreen","Widescreen","Docked")
ForEach($Entry in $List) {
ForEach($resolution in $resolutions) {
# Prepend the destination directory info for RDP files
$Dir = "..\" + $resolution + "\" + $Entry.Directory
# Create new folder
New-Item -Path $Dir -ItemType Directory -Force
# Build the file name
$FileName = $Dir + "\" + $Entry.ServerName + ".RDP"
# Remove the old file if it exists
if(test-path $FileName)
{
Remove-Item $FileName -Force
}
# Begin building RDP file
$temp = "`nfull address:s:" + $Entry.IP
switch ($resolution) {
"Console" {
$temp += "`nscreen mode id:i:1"
$temp += "`ndesktopwidth:i:1024"
$temp += "`ndesktopheight:i:768"
$temp += "`nusername:s:" + $Entry.USER
#$temp += "`npassword 51:b:" + $Entry.PASS
$temp += "`npassword 51:b:" + $PWHash
#$temp += "`nadministrative session:i:1"
}
"Fullscreen" {
$temp += "`nscreen mode id:i:2"
$temp += "`nusername:s:" + $Entry.USER
#$temp += "`npassword 51:b:" + $Entry.PASS
$temp += "`npassword 51:b:" + $PWHash
}
"Widescreen" {
$temp += "`nscreen mode id:i:1"
$temp += "`ndesktopwidth:i:1152"
$temp += "`ndesktopheight:i:720"
$temp += "`nusername:s:" + $Entry.USER
#$temp += "`npassword 51:b:" + $Entry.PASS
$temp += "`npassword 51:b:" + $PWHash
}
"Docked" {
$temp += "`nscreen mode id:i:1"
$temp += "`ndesktopwidth:i:1152"
$temp += "`ndesktopheight:i:864"
$temp += "`nusername:s:" + $Entry.USER
#$temp += "`npassword 51:b:" + $Entry.PASS
$temp += "`npassword 51:b:" + $PWHash
}
}
$temp | out-file $FileName
write-host $temp
get-content template_bottom.txt >> $FileName
}
}
Beautiful!!! Love your input, and thanks SO much for sharing!!!! I found that the RDP Hash only works on the pc I ran the script on – good for security reasons
Thanks for the great information. Worked like a charm.
Do you know the line for the password field when using a gatewayserver ?
I am having problems with your script.
I did everything according to the instructions and I am ending up with the different directories containing just one file that does not connect to anything.
I made the csv file with the hostnames in columns 1 and 2, empty dir column and username and hashed pwds in colims 4 and 5.
The script that includes the passwords has a typo “Cullscreen” instead of “Fullscreen”. I changed this but still the script does not generate the desired connections.