如何使用带有来自 Powershell 的凭据的 [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer [英] How to use [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer with credential from Powershell

查看:22
本文介绍了如何使用带有来自 Powershell 的凭据的 [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须提供哪种凭据才能使其正常工作

Which kind of credentials must I provide, to get this working

$tfsServer = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($basePath,$credential)

我试过了:

$credential = New-Object System.Management.Automation.PsCredential($user,$password)  

$credential = New-Object System.Net.NetworkCredential($user, $password, $domane)

总是得到

Für "GetServer" und die folgende Argumenteanzahl kann keine Überladung gefunden werden: "2".
Bei Zeile:18 Zeichen:86
+ $tfsServer = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer <<<< ($basePath,$credential)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

我想用

TeamFoundationServerFactory.GetServer Method (String, ICredentialsProvider)

参见http://msdn.microsoft.com/en-us/library/bb136201%28v=vs.80%29.aspx

背景是,我想在远程 PowerShell 会话中调用它,但出于某种原因,我不明白

The background is, that I want to call this in a remote PowerShell session and for some reason, I do not understand

$tfsServer = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($basePath)

收益

TF30063:您无权访问 mytfs\MccCollection."

"TF30063: You are not authorized to access mytfs\MccCollection."

推荐答案

TeamFoundationServerFactory 需要一个 ICredentialsProvider 实现,正如@Berns_k 在他的回答中所示.如果您已经拥有凭据,您应该使用不同的方式来实例化您的 TfsTeamProjectCollection:

The TeamFoundationServerFactory expects a ICredentialsProvider implementation as @Berns_k shows in his answer. If you already have the credentials you should use a different way of instantiating your TfsTeamProjectCollection:

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
    new Uri("http://yourserver:8080/tfs/Collection"),
    new NetworkCredential("myuser", "myPassword", "mydomain");
);

或在 powershell 中:

or in powershell:

$cred = New-Object NetworkCredential("myuser", "myPassword", "mydomain")
$tpc = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
(
     $basePath,
     $cred
)

这样您就不需要创建凭据提供程序,并且您在第一次调用 EnsureAuthenticated 时不会出现任何错误.

That way you don't need to create a Credential Provider and you should not get any error on your first call to EnsureAuthenticated.

这篇关于如何使用带有来自 Powershell 的凭据的 [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆