2012-08-08 90 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)