2012-08-08 89 views
4

当我一台机器为什么TFS身份验证会在远程PowerShell会话中失败?

Add-Type -Path "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll" 

$basePath = "http://magv-dev-tfs:8080/tfs/MccCollection" 
[Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($basePath) 

我得到一个物体上直接运行下面的PowerShell脚本,与场AuthenticatedUserName,AuthenticatedUserDisplayName,AuthenticatedUserIdentity集。

当我运行在从某些其他机器使用samË凭证在同一台机器上的远程PowerShellTab相同的脚本,则这3个字段是emply:

AuthenticatedUserName   : 
AuthenticatedUserDisplayName : 
AuthenticatedUserIdentity  : 
Uri        : http://my-tfs:8080/tfs/mcccollection 
TimeZone      : System.CurrentSystemTimeZone 
InstanceId      : 
Name       : my-tfs\MccCollection 
Credentials      : System.Net.SystemNetworkCredential 
Culture       : de-DE 
SessionId      : 7c76a150-f681-4b3c-9b0d-2836a3a5a908 
ClientCacheDirectoryForInstance : 
HasAuthenticated    : False 
TfsTeamProjectCollection  : magv-dev-tfs\MccCollection 

编辑:

至少我发现了一个解决方法How to use [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer with credential from Powershell

+0

我刚碰上这个问题;我希望找到解决方法。 – 2013-01-15 23:06:56

回答

1

为invoke-command调用添加一个-credential参数?

1

当您使用Visual Studio TFS时,PowerShell可以访问连接到项目时注册的连接。 RegisteredTfsConnections提供了对注册连接的访问​​,所以你不必费心把你的凭证放入代码中。

以下片段连接到TFS服务器,并返回一个WorkItem。

 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client") 
$regProjCollection = [Microsoft.TeamFoundation.Client.RegisteredTfsConnections]::GetProjectCollection("tfs2010\TFS2010-MyCollection") 
$tfsTeamProjCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($regProjCollection) 
$ws = $tfsTeamProjCollection.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore") 
$ws.GetWorkItem(2525)