Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

The source control system in TFS (Team Foundation Server) 2008 is very useful. But unfortunately the user interface is limited and is missing some necessary features. Some of these missing features have been implemented in a separate tool called Team Foundation Sidekicks, which can be found at http://www.attrice.info/cm/tfs/index.htm. Microsoft has also released power tools for TFS 2008. They can be downloaded from here.

One of the things I have always missed in TFS is the ability to produce a list of files which have been changed (or deleted) within a certain timeframe. Sure, it is possible to view the history of a project in TFS, but this will produce a list of changesets and not a list of files. It is however possible to produce such a list of changed (or deleted) files by using powershell.

Let’s begin with starting up powershell by using the “PowerShell Console” in the “Microsoft Team Foundation Server 2008 Power Tools” menu. We are going to use the “Get-TfsItemHistory” command to retrieve a list of changes from TFS. The following command shows all changesets in the project “MyProject” which have been created within a certain timeframe:

Get-TfsItemHistory  "$/MyProject" -Version "D29/01/2010~D03/12/2019" -Recurse -IncludeItems `
-Server tfs-server-name

Note: In powershell the back tick (`) character is used as the continuation character. It tells powershell that the command continues on the next line. It is only used in this article to make the text more readable.

This command shows changesets, not files. To see the files within those changesets we need to expand the command:

Get-TfsItemHistory  "$/MyProject" -Version "D29/01/2010~D03/12/2019" -Recurse -IncludeItems `
-Server tfs-server-name | Select-Object -Expand "Changes"

When you review the output you will see that the list of files is not sorted and that it actually contains duplicate items. Furthermore, it may contain files resulting from tfs actions (like branching) in which we are not interested. The following command removes all files resulting from unwanted commands, removes all duplicates and sorts the list:

Get-TfsItemHistory  "$/MyProject" -Version "D29/01/2010~D03/12/2019" -Recurse -IncludeItems `
-Server tfs-server-name | Select-Object -Expand "Changes" | `
Where-Object { ($_.ChangeType `
	-band (Microsoft.TeamFoundation.VersionControl.Client.ChangeType::Delete `
	-bor Microsoft.TeamFoundation.VersionControl.Client.ChangeType::Merge `
	-bor Microsoft.TeamFoundation.VersionControl.Client.ChangeType::Branch) `
	) -eq 0 } | `
Select-TfsItem | Group-Object Path | Select-Object Name | Sort-Object Name

The output of this command look like this:


This command can be used as a starting point for making more advanced lists, e.g. lists containing only aspx-files or lists containing files changed by a certain person. Finally, here is a powershell command which shows all files which have been deleted within a certain timeframe:

Get-TfsItemHistory  "$/MyProject" -Version "D29/01/2010~D03/12/2019" -Recurse -IncludeItems `
-Server tfs-server-name | Select-Object -Expand "Changes" | `
Where-Object { ($_.ChangeType -eq Microsoft.TeamFoundation.VersionControl.Client.ChangeType::Delete ) } | `
Select-TfsItem | Select-Object Path | Sort-Object Path

 © Evident Interactive BV