我尝试使用Powershell连接到VSO。这是我的代码:
$tfsServer = New-Object System.Uri("the server is here")
$creds = [System.Net.CredentialCache]::DefaultNetworkCredentials
$tfsCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($tfsServer,$creds)
$tfsCollection.Authenticate()
当它到达Authenticate行时,会弹出一个框以供我输入我的凭据。我需要它不弹出这个框,因为这个脚本将被安排,我不能继续输入凭据。如何将当前用户的凭据传递给TFS对象?
答案 0 :(得分:3)
试试这个:
首先,运行此命令将提示您输入一次密码,然后以加密格式保存。
read-host -prompt Password -assecurestring | convertfrom-securestring | out-file .\ps-password.pwd -ErrorAction Stop
更改$ username变量
$Username = 'jdoe'
$Password = Get-Content ".\ps-password.pwd" | ConvertTo-SecureString
$creds = New-Object -typename System.Management.Automation.PSCredential -ArgumentList $Username,$Password
$tfsServer = New-Object System.Uri("the server is here")
$tfsCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($tfsServer,$creds)
$tfsCollection.Authenticate()
答案 1 :(得分:1)
使用constructor that just takes a URI。它将默认使用当前用户的凭据。
答案 2 :(得分:1)
要连接到Visual Studio Online,您必须按照Buck's post中的说明进行操作。不久:
$tfsServer = New-Object System.Uri("the server is here") $netCred = New-Object NetworkCredential("alternate_user","alternate_password") $basicCred = New-Object Microsoft.TeamFoundation.Client.BasicAuthCredential($netCred) $tfsCred = New-Object Microsoft.TeamFoundation.Client.TfsClientCredentials($basicCred) $tfsCred.AllowInteractive = $false $tfsCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($tfsServer,$tfsCred) $tfsCollection.EnsureAuthenticated()
我知道无法在VSO中使用当前进程凭据,但您必须明确传递它们。
答案 3 :(得分:0)
使用EnsureAuthenticated并且不指定凭据。
$tfsCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection("the server is here")
$tfsCollection.EnsureAuthenticated()
这样它将使用运行该过程的帐户。