Script to pull download all NuGet packages from a TFS feed
$tfsBaseUrl = "http://tfsserver:8080/tfs/P2U"
$feedName = "Libraries"
$feeds = Invoke-RestMethod "$tfsBaseUrl/_apis/Packaging/Feeds" -UseDefaultCredentials
$feed = $feeds.value | Where-Object { $_.name -eq $feedName }
$packageBaseUri = "$tfsBaseUrl/_packaging/$($feed.id)/nuget/v3/flat2"
$packages = $(Invoke-RestMethod "$($feed.url)/Packages" -UseDefaultCredentials)
foreach ($package in $packages.value)
{
foreach ($version in $package.versions.version)
{
$packageUri = "$packageBaseUri/$($package.name)/$version/$($package.name).$version.nupkg"
$outFile = "$($package.name).$($version).nupkg"
Write-Host "Package URL: $packageUri"
Write-Host "OutFile: $outFile"
Invoke-WebRequest $packageUri -UseDefaultCredentials -OutFile "$($package.name).$($version).nupkg"
}
}