Wednesday, October 15, 2014

Remote Desktop Menu Tool

This BAT files create a list of servers. Enter server list number to RDP into server. If you put "a" in front of the listing number for example a2, then will RDP using admin/console login.

Save to .bat file
echo off
REM V1 20110110 davisjs
REM V2 20110118 schneiderbi
REM V2 20110120 schneiderbi
SETLOCAL EnableDelayedExpansion

:: items in quotes appear as headings
set ServerNames="Heading Ttile",servername1, servername2

rem cls
set num=0
echo Choose Server for Remote Control:

:: loop through server names
FOR %%A in (%ServerNames%) DO (
REM %%~A strips any quotes around variable
REM if variable stripped f quotes equal variable then variable does not have quote
REM increment num and display
IF [%%~A]==[%%A] SET /A num+=1
IF [%%~A]==[%%A] echo [!num!] %%~%A
REM if variable has quote, then just display variable
IF NOT [%%~A]==[%%A] echo.
IF NOT [%%~A]==[%%A] echo %%~%A

SET consoleMode=false
SET /P M=Server?
::ECHO %M:~0,1%
:: if the first letter is lowercase a then run remotedesktop in console mode = true
IF "%M:~0,1%"=="a" SET consoleMode=true
::echo %consoleMode%
IF "%M:~0,1%"=="a" SET M=%M:~1,2%
::echo %M%"  
set num=0
FOR %%A in (%ServerNames%) DO (
IF [%%~A]==[%%A] SET /A num+=1
if "%m%"=="!num!" SET serverName=%%A
if "%m%"=="!num!" GOTO RD
if %m% ==q GOTO END
if %m% ==Q GOTO END

IF %consoleMode%==true (
start mstsc.exe /v:%serverName% /admin
) ELSE (
start mstsc.exe /v:%serverName%
rem start mstsc.exe /v:%serverName% /console


No comments:

Post a Comment