gpt4 book ai didi

Powershell 连接到 VSO

转载 作者:行者123 更新时间:2023-12-04 01:06:29 26 4
gpt4 key购买 nike

我正在尝试使用 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 对象?

最佳答案

试试这个:

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

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()

关于Powershell 连接到 VSO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25455085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com