In this script I am going to show how we can copy all the files available under a specified path to your local machine
- cls
- Write-Host "Enter source location " // your tfs path
- $sourceLocation = Read-Host
- $tfsCollectionUrl = New-Object System.URI($sourceLocation);
- Write-Host "Enter server path " // tfs source location $/MyFirstProject/
- $serverPath = Read-Host
- Write-Host "Enter local path to download" // your local folder
- $localPath = Read-Host
- [Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $tfsCollection = Get-TfsServer $tfsCollectionUrl
- $VersionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
- $latest = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest
- $recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
- try
- {
- foreach ($item in $VersionControl.GetItems($serverPath, $latest,$recursionType).Items)
- {
- $target = [io.path]::Combine($localPath,$item.ServerItem.Substring(2))
- $exists=[System.IO.Directory]::Exists($target)
- if($item.ItemType -eq "Folder" -and !$exists)
- {
- New-Item $target -Type Directory
- }
- if($item.ItemType -eq "File")
- {
- $item.DownloadFile($target)
- }
- }
- Write-Host "`n Successfully downloaded all the files to the target folder: " $localPath -ForegroundColor Green
- }
- catch
- {
- $ErrorMessage = $_.Exception.Message
- $FailedItem = $_.Exception.ItemName
- Break
- }
No comments:
Post a Comment