Reputation: 11966
When I run the following PowerShell script directly on a machine
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)
I get an objects, with the fields AuthenticatedUserName, AuthenticatedUserDisplayName, AuthenticatedUserIdentity set.
When I run the same script in a remote PowerShellTab from some other machine on the same machine using the sam e credentials, then these 3 fields are 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
Edit:
At least I found a work around How to use [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer with credential from Powershell
Upvotes: 4
Views: 956
Reputation: 41
When you use Visual Studio TFS, PowerShell can access the connections that you have registered when you connected to your project. RegisteredTfsConnections provides access to the registered connections, so you don't have to bother with putting your credentials into the code.
The following snippet connects to a TFS server, and returns a 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)
Upvotes: 1