Created
October 13, 2016 02:07
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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