Last active
December 14, 2015 02:49
-
-
Save kfrancis/5016326 to your computer and use it in GitHub Desktop.
Untested script updated for VS2012 from http://blog.donnfelker.com/2009/01/22/powershell-tfs-workspace-initialization-script/
This file contains hidden or 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
# Script that will: | |
# 1. Create a workspace. Workspacce Name: <ComputerName>_Root | |
# 2. Get the latest code from repository | |
# TODO: This needs to handle making workspace PER PROJECT, which it doesn't yet. | |
# TODO: It should create a local directory for each project in TFS, along with the workspace to download the files. | |
[string] $tfsDomain = "foo" | |
[string] $tfsServer = "https://" + $tfsDomain + ".visualstudio.com/defaultcollection" | |
[string] $userName = [system.environment]::UserName; | |
[string] $computerName = [system.environment]::machinename | |
[string] $workspaceName = $computerName + "_" + $userName +"_WS" #Use 'WS' as an acronym for "WorkSpace" | |
[string] $folderName = "C:\Projects"; | |
# Clear Output Pane | |
clear | |
# Loads Windows PowerShell snap-in if not already loaded | |
if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | |
{ | |
Add-PSSnapin Microsoft.TeamFoundation.PowerShell | |
} | |
# Set up the TF Alias</pre> | |
# Find where VS is installed. | |
$key = Get-ItemProperty -path HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0 | |
$dir = [string] (Get-ItemProperty $key.InstallDir) | |
Set-Alias tf "$dir\tf.exe" | |
Write-Progress -Activity "Initializing Tree" -Status "Percentage Complete" -PercentComplete(10) | |
# Create the folder | |
echo "Creating folder: $folderName" | |
new-item -itemtype directory -path $folderName -force | |
echo "Completed Creating folder: $folderName" | |
[system.environment]::newline | |
Write-Progress -Activity "Initializing Tree" -Status "Percentage Complete" -PercentComplete(20) | |
# Move to folder | |
echo "Navigating to $folderName..." | |
cd $folderName | |
echo "Arrived at $folderName" | |
[system.environment]::newline | |
Write-Progress -Activity "Initializing Tree" -Status "Percentage Complete" -PercentComplete(30) | |
# Delete the workspace if it exists. | |
echo "Deleting workspace (if exists): $workspaceName" | |
$expr = "tf workspace /delete " + $workspaceName + " /noprompt" | |
$output = invoke-expression $expr | |
echo "Done deleting workspace." | |
[system.environment]::newline | |
Write-Progress -Activity "Initializing Tree" -Status "Percentage Complete" -PercentComplete(40) | |
# Create the workspace | |
echo "Creating workspace: $workspaceName" | |
$expr = [system.string]::Format("tf workspace /new /computer:{0} /server:{1} /noprompt {2}", $computerName, $tfsServer, $workspaceName) | |
$output = invoke-expression $expr | |
echo "Done Creating workspace: $workspaceName" | |
[system.environment]::newline | |
Write-Progress -Activity "Downloading Entire Source Tree" -Status "% Complete - this bar will not move for awhile. This process takes awhile." -PercentComplete(50) | |
# Get the latest | |
echo "Getting the latest code from: $tfsServer. This could take awhile..." | |
$expr = "tf get"; | |
$output = invoke-expression $expr | |
echo "Done getting latest." | |
Write-Progress -Activity "Initializing Tree" -Status "Percentage Complete" -PercentComplete(100) | |
echo "Tree initialization is complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment