PowerShell Cmdlets for Team Foundation Server and Visual Studio Team Services
TfsCmdlets is a PowerShell module which provides many commands ("cmdlets" in PowerShell parlance) to simplify automated interaction with Team Foundation Server and Visual Studio Team Services.
By using TfsCmdlets, TFS administrators (even power users) can create scripts to automate many different tasks, ranging from retrieving work items to create new team project collections.
TfsCmdlets is available in many formats. The full (MSI-based) installer also includes Team Foundation Server Shell, a PowerShell window pre-configured to make interacting with TFS via command line a joy!
Firstly, download and configure the 2013 version of the Visual Studio Team Foundation Server Virtual Machine (a.k.a "Brian Keller VM") in your computer in order to have a sandbox to play with.
Next, install TfsCmdlets inside the virtual machine (see section "How to install", below), open a PowerShell window and try the following commands:
# Connect to the FabrikamFiber team project collection
# (Will be used as default for the -Collection argument when required by a cmdlet)
Connect-TfsTeamProjectCollection http://vsalm:8080/tfs/FabrikamFiberCollection
# Get a list of team projects in the currently connected TPC
Get-TfsTeamProject
# List the existing iterations in the FabrikamFiber team project
Get-TfsIteration -Project FabrikamFiber
# Connect to the FabrikamFiber team project
# (will be used as default for the -Project argument when required by a cmdlet)
Connect-TfsTeamProject FabrikamFiber
# Create a new iteration
New-TfsIteration 'Release 3'
# Get all bugs in the current team project
Get-TfsWorkItem -Filter '[System.WorkItemType] = "Bug"'
# Create a new PBI in the 'Release 3' iteration
New-TfsWorkItem -Title 'New product backlog item' -Type 'Product Backlog Item' -Fields @{'System.IterationPath'='Release 3'}
TfsCmdlets can be obtained from many different sources and in many different formats. Choose the one most suitable to you!
If you're using Windows 10, Windows Server 2016 or installed Windows Management Framework 5 then the simplest way to install TfsCmdlets is via PowerShell Gallery.
Open an elevated PowerShell prompt and type:
Install-Module TfsCmdlets
Using Chocolatey? Then open an elevated PowerShell prompt and type:
# To install the latest pre-release (alpha, beta) version of TfsCmdlets, type:
choco install TfsCmdlets -pre
# To install the latest final release version of TfsCmdlets, type:
choco install TfsCmdlets
Nuget is a great option if you need to integrate TfsCmdlets with your continuous integration process (e.g. you need to create a TFS work item during the execution of an automated build).
To add TfsCmdlets to your solution, search for TfsCmdlets in the Visual Studio "Manage Nuget packages for solution..." dialog.
- Note: To add the latest pre-release version of TfsCmdlets, don't forget check the "Include prerelease" checkbox
When the target machine is not connected to the internet, none of the options above are available. In that case, your best bet is one of the offline installation alternatives below.
You can get one of the offline installers listed below from the GitHub Releases page.
The full installer will install the module files to the Program Files folder in your computer, make the module available to PowerShell and create the Team Foundation Server Shell icon in the Start Menu.
To install the full installer:
- Download the MSI file from the Releases page;
- Open the downloaded MSI file
- NOTE: If Windows SmartScreen flags the file as insecure and refuses to run it, you can click the "More info" button/link in the dialog and select the "Run anyway" option.
To uninstall the full installer:
- Use the Programs and Features (formerly "Add and remove programs") function in the Windows Control Panel.
The portable installer is a zip file containing all the required the module files.
To install the portable installer:
- Download the zip file from the Releases page;
- Open your Documents folder in Windows, then open the
WindowsPowerShell
folder in it; - Inside the WindowsPowerShell folder, create a new folder called
Modules
in it (if missing); - Extract the contents of the zip file to the
Modules
folder.
You must end up with a folder structure similar to [Documents]\WindowsPowerShell\Modules\TfsCmdlets
. Files such as TfsCmdlets.psd1
must be located in the TfsCmdlets folder.
To test the installation, open a new PowerShell window and type:
Import-Module TfsCmdlets
To uninstall the portable installer
- Close all PowerShell windows where you were using TfsCmdlets (to free files in use);
- Delete the
TfsCmdlets
folder from the[Documents]\WindowsPowerShell\Modules
folder.
Coming soon.