Wednesday, September 17, 2008

Get List of File Associated with multiple Changesets

I wrote a cmdlet for powershell by which you can get list of file associated with list of changesets.
param(
[string] $changesets = $(throw 'Usage: Get-Changeset-Files 'changesets')
)

process
{
# get TFS object
$tfs = get-tfs ;

# build up list of file items
$fileItems = @();

$changesets.Split(',') | foreach {
$tfs.vcs.GetChangeset($_).Changes | foreach {
if($fileItems -notcontains $_.Item.ServerItem) {
$fileItems += $_.Item.ServerItem;
}
}
}
return $fileItems | Sort-Object;
}


Steps:
1. Create a file Get-Changeset-Files.ps1 and copy above code in the file (preferably where get-tfs resides). Also add this directory into your $path
2. Open Powershell, go to Directory where above file recides
3. Run 'Set-ExecutionPolicy unrestricted' so that you can run above cmdlet
4. Everything is ready.. just run for example: Get-Changeset-Files('10, 20, 30')

See here for get-tfs.ps1

2 comments:

Anonymous said...

I'm getting the following errror

Unexpected token 'changesets')
)

process
{
# get TFS object
$tfs = get-tfs ;

# build up list of file items
$fileItems = @();

$changesets.Split('' in expression or statement.
At C:\Users\Zeppelin\Documents\Visual Studio 2008\Get-Changeset-Files.ps1:13 char:25
+ [string] $changeset <<<< s = $(throw 'Usage: Get-Changeset-Files 'changesets')
+ CategoryInfo : ParserError: (changesets')
)...ngesets.Split(':String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken

Yogee said...

Did you define

param(
[string] $changesets = $(throw 'Usage: Get-Changeset-Files 'changesets')
)

section above your process? or did you change $changesets to some other variable?