Everyday Nerd
Just your everyday nerd
-
Sep137 Comments
RDP - Remote Desktop Connection, or what we called back in the day, Terminal Services. Every system administrator uses it daily. At work, the team I work on has 145 servers that we are responsible for, and only a handful of them are in the same building as us (although we still remote into them as well).
This being said, I was getting tired of typing in the server’s name or IP address every time I needed to connect to it. I know Microsoft has an mmc for Remote Desktops, but I just don’t like the clunky way it has to be setup, plus, did I mention I had 145 to put in? Well, call me lazy, but I knew there had to be a way to script it - after all, a RDP file is nothing but some text (open a .rdp file with notepad - you’ll see!).
So, enough background, lets do some scripting! There are 3 files here: Powershell script, a CSV file, and a Text file.
- First, the CSV File: It has 4 columns with the first row being the headers. Do not change row. Name this file RDPLIST.csv
ServerName,IP,Directory,USER
FRIENDLYNAME,FQDNorIP,FOLDERNAME\SUBFOLDER,DOMAIN\USERNAME- Next, is the Text File. This contains other parameters that are going to be the same between every connection - such as enabling shared clipboard, 16bit colors, disable themes, etc. You can customize this to your liking (to get it just the way you want it, create an .rdp file, and edit it with notepad, and you will see a list similar to below). Name this file template_bottom.txt
audiomode:i:2
authentication level:i:0
autoreconnection enabled:i:1
bitmapcachepersistenable:i:1
compression:i:1
disable cursor setting:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:1
disable wallpaper:i:1
displayconnectionbar:i:1
keyboardhook:i:2
redirectclipboard:i:1
redirectcomports:i:0
redirectdrives:i:0
redirectprinters:i:0
redirectsmartcards:i:0
session bpp:i:16
prompt for credentials:i:0
promptcredentialonce:i:1- Lastly, the Powershell script: Name this file CreateRDP.ps1
1: $List = Import-CSV RDPLIST.CSV2: $resolutions = ("1024x768","1152x864")
3: ForEach($Entry in $List) {
4: ForEach($resolution in $resolutions) {
5: # Prepend the destination directory info for RDP files
6: $Dir = "..\" + $resolution + "\" + $Entry.Directory
7:8: # Create new folder9: New-Item -Path $Dir -ItemType Directory -Force10:11: # Build the file name12: $FileName = $Dir + "\" + $Entry.ServerName + ".RDP"
13:14: # Remove the old file15: Remove-Item $FileName -Force16:17: # Begin building RDP file18: $temp = "`nfull address:s:" + $Entry.IP
19:20: switch ($resolution) {21:22: "1024x768" {
23: $temp = $temp + "`nscreen mode id:i:1"
24: $temp = $temp + "`ndesktopwidth:i:1024"
25: $temp = $temp + "`ndesktopheight:i:768"
26: $temp = $temp + "`nusername:s:" + $Entry.USER
27: }28:29: "1152x864" {
30: $temp = $temp + "`nscreen mode id:i:1"
31: $temp = $temp + "`ndesktopwidth:i:1152"
32: $temp = $temp + "`ndesktopheight:i:864"
33: $temp = $temp + "`nusername:s:" + $Entry.USER34: }35: }36: $temp | out-file $FileName37: write-host $temp38: get-content template_bottom.txt >> $FileName39: }40: }Now, you need a folder structure:
- Powershell_RDP
- rdp
- _script
Put all three files in the _script folder.
- rdp
And just because I’m a nice guy, here’s a zip of the files and the correct folder structure. Just unzip, make your edits to the csv file, save and close it, and open PowerShell (as Administrator if using Vista) and navigate to the _Script folder. Once there, run the CreateRDP.ps1 (put a ./ in front of the filename)
Feel free to customize this script to your own liking! It’s a simple script, so it shouldn’t be too hard to mess with. It works like a CHARM!!! I created 290 RDP files in less than 30 seconds! Great thing is, it creates a separate folder structure for the different resolutions (I used 1024×768 & 1152×864 because my laptop is a widescreen, but when I’m docked, it’s a standard monitor).
One more tip, I made two new toolbars, and pushed them all the way over to the right of the taskbar, making a nifty little launcher!
Hope you enjoy this - I know I did! It took me longer to write this post than it did to get all my .RDP file!
-
Aug6
VBS to EXE
Filed under: Scripts;3 CommentsI use a LOT of scripts. I sometimes will roll out a script to users, or other people on the IT staff. There are times that I would rather they not see the source of the script for various reasons. Answer to this? VBS to EXE!
VbsToExe is a command line application that converts VB-Scripts into an executable. This utility hides the source of your scripts and protects them optionally with a password.
-
Jul26
Script: Who’s Logged on to remote PC
Filed under: Scripts;2 CommentsIf you manage a network, you know how useful it is to be able to know who is logged on a remote machine. Here is a VB Script that will tell you exactly that!
ComputerName = InputBox("Enter the name of the computer you wish to query")
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
Set UserSet = GetObject( winmgmt1 ).InstancesOf ("Win32_ComputerSystem")
for each User in UserSet
MsgBox "The user name for the specified computer is: " & User.UserName
Next.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }Copy the above code, save it as a vbs file, run it, enter the machine name, and it returns the logged on user! Simple as that! Note, you must be an administrator of the machine that you want to query.




