Skip to content

Instantly share code, notes, and snippets.

@josy1024
Last active January 14, 2016 17:16
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 josy1024/917715eef3a87a3c0bf3 to your computer and use it in GitHub Desktop.
Save josy1024/917715eef3a87a3c0bf3 to your computer and use it in GitHub Desktop.
prestage remote desktop logons for other users
# prestage remote desktop logons for other users... (have to know passwords #
# author: josef lahmer
#
# USE https://gallery.technet.microsoft.com/scriptcenter/Connect-Mstsc-Open-RDP-2064b10b
# https://gist.github.com/josy1024/917715eef3a87a3c0bf3
# optimisations:
# (would be nice to know if i can store password hashes)? (to avoid clear text passwords)
# run this script bevor the users are going to work (you have to know their passwords!!)
# autoadminlogon on reboot on terminalservers?
. .\Connect-Mstsc.ps1
# or from network
# . "\\server\share\Connect-Mstsc.ps1"
# for every line change server and logon credentials
Connect-Mstsc -ComputerName servername -User 'domain\user' -Password 'password'
## option with secure password string....
$user = "domain\user"
$passwordfile="passwordfile.txt"
### set password with:
# read-host -assecurestring | convertfrom-securestring | out-file passwordfile.txt
$pass = (get-content -path $passwordfile | convertto-securestring)
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$pass
Connect-Mstsc -ComputerName servername -Credential $cred
#
# ....
# wait 3 minutes to sure logonprocess finished...
start-sleep 180
# reset mstsc connections for this user session
taskkill /F /FI "USERNAME eq %USERNAME%" /IM "mstsc.exe"
# wait for the useres to go to work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment