Skip to content
Create a gist now

Instantly share code, notes, and snippets.

A PowerShell script to wrap the `tfpt.exe createteamproject` process for creating a new Team Project in Team Foundation Server
# requires -version 2.0
param (
[parameter(Position=0, Mandatory=$true)]
$CollectionUri, # eg 'http://tfsserver:8080/tfs/DefaultCollection'
[parameter(Position=1, Mandatory=$true)]
$ProjectName, # eg 'MyNewProject'
[parameter(Position=2, Mandatory=$true)]
$ProcessTemplateName # eg 'Microsoft Visual Studio Scrum 2.0'
if (-not $Env:TFSPowerToolDir) {
throw "Environment variable 'TFSPowerToolDir' is not set. You may need to restart the computer after installing the TFS Power Tools."
$TfptExe = Join-Path -Path $Env:TFSPowerToolDir -ChildPath tfpt.exe
if (-not (Test-Path -Path $TfptExe -PathType Leaf)) {
throw 'Team Foundation Server Power Tools must be installed.'
if (Get-Process | Where-Object { $_.Name -eq 'devenv' }) {
Write-Warning 'For best results, close running instances of Visual Studio before proceeding. Waiting 10 seconds...'
Start-Sleep -Seconds 10
$WorkingPath = Join-Path -Path $Env:TEMP -ChildPath ([Guid]::NewGuid())
New-Item -Path $WorkingPath -ItemType Container | Out-Null
$XmlDoc = [xml]@"
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="ProjectCreationSettingsFileSchema.xsd">
$XmlDoc.Project.TFSName = $CollectionUri
$XmlDoc.Project.LogFolder = [string]$WorkingPath
$XmlDoc.Project.ProjectName = $ProjectName
$XmlDoc.Project.ProjectSiteTitle = $ProjectName
$XmlDoc.Project.ProcessTemplateName = $ProcessTemplateName
& $TfptExe createteamproject /settingsfile:"$WorkingPath\settings.xml" 2>&1 |
Tee-Object -Variable ExeResult
$LogResult = $WorkingPath | Get-ChildItem -Exclude settings.xml | Get-Content
Remove-Item -Path $WorkingPath -Force -Recurse
if ($ExeResult -is [System.Management.Automation.ErrorRecord]) {
throw "Failed to create new team project:`n$ExeResult"
if ($TfptExitCode -or $LogResult -match 'exception') {
throw "Failed to create new team project:`n$LogResult"
"Project created."

Nice! Do you know how to specify the Project Description?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.