Last active
January 28, 2021 11:13
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use (assuming you put a shortcut on Windows Taskbar):
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:
A Python version with the same functionality can be found here.
A .bat version with the same functionality can be found here