Powershell连接到VSO

Powershell连接到VSO,powershell,authentication,tfs,azure-devops,Powershell,Authentication,Tfs,Azure Devops,我正在尝试使用Powershell连接到VSO。这是我的密码: $tfsServer = New-Object System.Uri("the server is here") $creds = [System.Net.CredentialCache]::DefaultNetworkCredentials $tfsCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($tfsServer,

我正在尝试使用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()
当它到达认证行时,它会弹出一个框供我输入凭据。我需要它不要弹出这个框,因为这个脚本将被安排,我不能继续输入凭据。如何将当前用户的凭据传递给TFS对象?

请尝试以下操作:

首先,运行这个命令,它会提示您输入密码一次,然后以加密格式保存

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()
使用。它将默认使用当前用户的凭据。

使用和不指定凭据

$tfsCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection("the server is here")
$tfsCollection.EnsureAuthenticated()

这样,它将使用运行进程的帐户。

要连接到Visual Studio Online,您必须按照中的说明进行操作。很快:

  • 在VSO帐户上启用备用凭据
  • 设置备用用户和密码
  • 使用与以下类似的代码

  • 我不知道如何在VSO中使用当前进程凭据,但您必须显式地传递它们。

    这只是将“jdoe”的凭据传递给TFS。我想让它获取当前登录的用户,无论脚本以谁的身份运行。$Username=$env:Username或者如果需要包含域:$Username=$env:USERDOMAIN+'\'+$env:Username,但是它怎么知道使用哪个密码文件呢?它仍然会弹出一个窗口,要求我登录。我假设您使用TFS内部部署和IE配置(与.Net共享)是正确的--“自动登录”区域。如果目标TFS位于另一个域/工作组,则必须使用凭据管理器。啊,我认为这就是我的问题。我不是在Premisis上使用TFS,我使用的是TFS online(server.visualstudio.com)。我认为这是TFS online进行身份验证的方式的问题。
    $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()