使用Powershell下载TFS文件时,如何解决无效URI错误
我有一个powershell脚本从TFS目录下载项目 代码如下:使用Powershell下载TFS文件时,如何解决无效URI错误,powershell,tfs,Powershell,Tfs,我有一个powershell脚本从TFS目录下载项目 代码如下: $TfsWorkspace = "$/Region/Application/Master/Payments" $TfsUri = "http://tfs.company.net:8080/tfs/global" $LocalDir = "C:\Deployment\" Add-PSSnapin Microsoft.TeamFoundation.PowerShell # Connect to TFS $TFSServer = G
$TfsWorkspace = "$/Region/Application/Master/Payments"
$TfsUri = "http://tfs.company.net:8080/tfs/global"
$LocalDir = "C:\Deployment\"
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
# Connect to TFS
$TFSServer = Get-TfsServer -Name $TfsUri
# Get all directories and files in the $TfsWorkspace directory
$items = Get-TfsChildItem $TfsWorkspace -Recurse -Server $TFSServer
$tfsCollection = New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $TfsUri
$tfsVersionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
# Download each item to a specific destination
foreach ($item in $items)
{
#If it finds a folder create the folder first
if ($item.ItemType -eq "Folder")
{
$newFolder = ($LocalDir + $([IO.Path]::GetFullPath($item.ServerItem.Remove(0,1)).Remove(0,3)))
New-Item -ItemType directory -Path $($newFolder) -Force
}
else
{
$newFile = $($LocalDir + $([IO.Path]::GetFullPath($item.ServerItem.Remove(0,1)).Remove(0,3)))
$tfsVersionControl.DownloadFile($item.ServerItem, $newFile)
}
}
当我运行此脚本时,它会在驱动器上创建文件夹,但当它点击零件以创建新文件时,我会收到以下错误消息:
Exception calling "DownloadFile" with "2" argument(s): "Invalid URI: Invalid port specified."
At C:\Users\UKAutoUser\Documents\TFS_Update2.ps1:40 char:9
+ $tfsVersionControl.DownloadFile($item.ServerItem, $newFile)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : UriFormatException
我试着从文档中找出那个错误,但似乎没有什么意义。因为它的连接很好,因为它找到了项目
下面是传递到DownloadFile方法的字符串值的示例:
C:\Deployment\Region\Application\Master\Payments\Screens.cs
$/Region/Application/Master/Payments/Screens.cs
任何帮助都将不胜感激。我似乎快到了,因为我可以得到一个我正在迭代的文件列表。我只需要能够下载到部署文件夹
这就是我以后可以使用Jenkins构建代码的原因。您为什么不使用?@JamesReed?我是,但它只允许您从一个位置下载源代码。我需要从几个不同的地方下载源代码。