Skip to content

Instantly share code, notes, and snippets.

@flow4u
Last active January 28, 2021 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flow4u/f97ac2a5998ea02ee95216f442448c41 to your computer and use it in GitHub Desktop.
Save flow4u/f97ac2a5998ea02ee95216f442448c41 to your computer and use it in GitHub Desktop.
PS1: MyDRE easy open session with 2 monitors (mutlimonitor is restricted to 2), also works with 1
# This script for Windows make it easier to run RDP files on Windows
# After downloading the RDP, run this script
# It picks up the latest RDP-file from downloads, copies it to MyDRE.RDP
# Adds a few lines to the RDP for magic (customize in the section: CUSTOM
# Deletes the downloaded RDP file to prevent clutter in your Downloads
# Runs the script
# CUSTOMIZATION
# Par3: select the monintors to be used, make sure these monitors are adjecent
# E.g.: 0,1 = Use Monitor 0 and 1
$Par1 = "span monitors:i:1"
$Par2 = "use multimon:i:1"
$Par3 = "selectedmonitors:s:0,1"
# Declaring variables
$Location = "$HOME\Downloads"
$SearchFor = "*.rdp"
$SearchString = $Location + "\" + $SearchFor
$MyDRE = $Location + "\MyDRE.rdp"
# Finds the latest RDP-file in downloads and ends script if no RDP-file is present
$Newestfile = Get-ChildItem -Path $SearchString | Sort CreationTime -Descending | Select-Object -First 1
echo $Newestfile
# If no RDP file is present, exit the script
if ($Newestfile -eq $null)
{
echo "No RDP-file present"
Exit
}
# When latest RDP is not MyDRE.RDP, copy latest RDP to MyDRE.rdp and add a few lines
# And delete the latest RDP
if ($Newestfile -notlike $MyDRE)
{
copy-item -path $Newestfile -destination $MyDRE
add-content $MyDRE ""
add-content $MyDRE $Par1
add-content $MyDRE $Par2
add-content $MyDRE $Par3
remove-item $Newestfile
}
# Open MyDRE.rdp
Start-Process "$env:windir\system32\mstsc.exe" $MyDRE
@flow4u
Copy link
Author

flow4u commented Jan 27, 2021

How to use (assuming you put a shortcut on Windows Taskbar):

  1. Download the RDP file as usual
  2. Press MyDRE RDP icon on the Windows Taskbar
  3. Fill in your details, and if you have 2 or more monitors, monitor 0 and 1 (and only those) will be used for the VM
  • In the background the downloaded RDP file will be deleted (preventing cluttering your downloads)
  • It always takes the latest RDP file (either downloaded, or modified by the script)
  • You can download a nice icon: app.ico.

Alternatively, download the app powershell.zip. Extract it in c:\users\public\shortcuts and drag the MyDRE - Powershell Shortcut to Windows task bar and you're good to go.

Some organizations block zips with extensions, use this zip and read the instructions included in the zip.

A small modification, already in the zip, of the shortcut was needed in order to be able to put it on the Windows Taskbar:
The shortcut has:

  • Target: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\Users\Public\Shortcuts\MyDRE.ps1
  • Start in: C:\Users\Public\Desktop
  • Change icon: %SystemDrive%\Users\Public\Shortcuts\app.ico

A Python version with the same functionality can be found here.
A .bat version with the same functionality can be found here

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