Skip to content

Instantly share code, notes, and snippets.

@clintcparker
Created October 13, 2016 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clintcparker/ee92d2e6faa45614e2c41afbd33884ed to your computer and use it in GitHub Desktop.
Save clintcparker/ee92d2e6faa45614e2c41afbd33884ed to your computer and use it in GitHub Desktop.
How to get specific version of folder from tfs without creating a workspace?
function Get-LocalCopy {
[CmdletBinding()]
param(
[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='What tfs item(s) would you like to copy?')]
[string]$itemspec,
[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Where will it be mapped to?')]
[string]$output,
[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='What is the tfs collection URL?')]
[string]$collection,
[Parameter(
Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='What version to get?')]
[string]$version,
[switch]$noMessage
)
if (!$noMessage)
{
echo "Copying $itemspec to $output..."
}
$tfDirArgs = $itemspec + " /collection:$collection "
if ($version -ne "")
{
$tfDirArgs = $tfDirArgs + " /version:$version "
}
$items = Invoke-Expression $("tf dir $tfDirArgs")
foreach($item in $items)
{
if ($item -inotmatch "[:\(]" -and $item -ne "")
{
#echo $item
if ($item -match "\$") #directory
{
$directoryName = $item.Replace("$","");
Get-LocalCopy -itemspec $($itemspec + "/" + $directoryName) -output $($output + "/" + $directoryName) -collection $collection -version:$version -noMessage;
}
else #file
{
$tfViewArgs = $($itemspec + "/" + $item) + " /collection:$collection " + " /output:$($output + "/" + $item) "
if ($version -ne "")
{
$tfViewArgs = $tfViewArgs + " /version:$version "
}
$tfViewCommand = $("tf view $tfViewArgs")
$outVal = $(Invoke-Expression $tfViewCommand)
}
}
}
if (!$noMessage)
{
echo "...complete"
dir $output
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment