Reputation: 330
I'm trying to use Powershell to connect to VSO. Here is my code:
$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()
When it reaches the Authenticate line, it pops up a box for me to enter my credentials. I need it to not pop up this box, as this script will be scheduled, and I can't keep entering the credentials. How can I pass the current user's credentials to the TFS object?
Upvotes: 3
Views: 4356
Reputation: 8343
To connect to Visual Studio Online, you have to follow the instructions at Buck's post. Shortly:
$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()
I know no way of using current process credentials with VSO, but you must explicitly pass them.
Upvotes: 1
Reputation: 8343
Use EnsureAuthenticated and do not specify credentials.
$tfsCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection("the server is here")
$tfsCollection.EnsureAuthenticated()
This way it will use the account running the process.
Upvotes: 0
Reputation: 59020
Use the constructor that just takes a URI. It will default to using the credentials of the current user.
Upvotes: 1
Reputation: 61
Try this:
First, run this command which will prompt you once for your password, and then save it in an encrypted format.
read-host -prompt Password -assecurestring | convertfrom-securestring | out-file .\ps-password.pwd -ErrorAction Stop
Change the $username variable
$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()
Upvotes: 3