Skip to content

Instantly share code, notes, and snippets.

@lookitstony
Created March 17, 2016 18:36
Show Gist options
  • Select an option

  • Save lookitstony/431f769488c67e74413f to your computer and use it in GitHub Desktop.

Select an option

Save lookitstony/431f769488c67e74413f to your computer and use it in GitHub Desktop.
Batch file to setup TFS a distributed VM that multiple people will be using.
@echo off
SET me=%~n0
SET parent=%~dp0
SET log=%TEMP%\%me%.txt
SET %ERRORLEVEL%=0
echo ============================================
echo %me%
echo ============================================
:AdminCheck
net session >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
ECHO.
) ELSE (
ECHO Must run as an Administrator. Exiting...
ECHO.
EXIT /B 1
)
:DeleteWarning
echo.
echo WARNING! This will delete all code in C:\TFS so make sure
echo all of your code is committed or your code will be lost!!!
echo.
set /p accept=To continue deleting type 'y':
if not "%accept%" == "y" exit
:StartProcess
cls
echo ============================================
echo %me%
echo ============================================
echo.
:: get user name used to create name directory and workspace name
set /p userDir=Network Username:
:: set script variables
set sourceBase=C:\TFS
set sourcePath=%sourceBase%\%userDir%
set sourceWidgetPath=%sourcePath%\Widgets
set sourceProviderPath=%sourcePath%\Providers
:: set TFS related variables
set tfsCollection=[TFSSERVER]
set workspaceName=%userDir%-SDK
set tfsWidgetPath=[$/TFSPATH]
set tfsProviderPath=[$/TFSPATH]
:: set symlinked destination paths
set sdkWidgetPath=C:\SDK\Widgets
set sdkProviderPath=C:\SDK\Providers
:: launch VsDevCmd so we can execute tfs commands
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"
:DeleteDirectories
echo.
echo ## Delete TFS Directory ##
del /q /s /f "%sourceBase%\*" 1>nul
for /d %%x in ("%sourceBase%\*") do @rd /s /q "%%x"
:CreateDirectory
echo.
echo ## Create TFS Directory ##
mkdir %sourcePath%
cd %sourcePath%
:SetupWorkspace
echo.
echo ## Creating TFS Workspace %workspaceName% ##
:: create workspace
tf workspaces /remove:*
tf workspace /new %workspaceName% /collection:%tfsCollection% /noprompt
:: map specific folders
tf workfold /map %tfsWidgetPath% %sourceWidgetPath% /collection:%tfsCollection% /workspace:%workspaceName%
tf workfold /map %tfsProviderPath% %sourceProviderPath% /collection:%tfsCollection% /workspace:%workspaceName%
::remove base path mapping
tf workfold /unmap $/ /collection:%tfsCollection% /workspace:%workspaceName%
pause
:GetSourceCode
echo.
echo ## Get Latest Source Code ##
tf get %tfsWidgetPath% /recursive
tf get %tfsProviderPath% /recursive
:CreateSymLink
cls
echo.
echo ## Setup Widget and Provider SymLinks ##
:: remove target folders if exist
IF EXIST %sdkWidgetPath% RD /q /s %sdkWidgetPath%
IF EXIST %sdkProviderPath% RD /q /s %sdkProviderPath%
:: create symlinks
mklink /D %sdkWidgetPath% %sourceWidgetPath%
mklink /D %sdkProviderPath% %sourceProviderPath%
cls
echo ============================================
echo %me% [Completed]
echo ============================================
echo.
echo Workspace Created: %workspaceName%
echo.
echo Widget Source: %sourceWidgetPath%
echo Widget Working Directory: %sdkWidgetPath%
echo.
echo Provider Source: %sourceProviderPath%
echo Provider Working Directory: %sdkProviderPath%
echo.
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment