TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Copy Entire Files From TFS To Local Using PowerShell
Dorababu Meka
Jul 22
2016
Code
7
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
C
cls
Write-Host
"Enter source location "
$sourceLocation
= Read-Host
$tfsCollectionUrl
= New-Object System.URI(
$sourceLocation
);
Write-Host
"Enter server path "
$serverPath
= Read-Host
Write-Host
"Enter local path to download"
$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
}
PowerShell
TFS
Copy Entire Files