Skip to content

Instantly share code, notes, and snippets.

@RafPe
Created August 26, 2015 10:36
Show Gist options
  • Save RafPe/bdbfb1d3bd8d4a6df2c9 to your computer and use it in GitHub Desktop.
Save RafPe/bdbfb1d3bd8d4a6df2c9 to your computer and use it in GitHub Desktop.
$tfsurl = 'https://tfs.someservername:8088/tfs/SomeAwesomeCollection'
$username = 'administrator'
$domain = 'MyCompany'
$password = 'Password1'
# Create URI
$tfs_uri = [System.Uri]::new( $tfsurl )
# Create server object
$_tfs_server = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfs_uri, $false, $fale)
# Create credentials object and assign them to server
$cred = New-Object System.Net.NetworkCredential($username,$password,$domain)
$_tfs_server.Credentials = $cred
# Authenticate
try
{
$_tfs_server.EnsureAuthenticated()
return $_tfs_server
}
catch
{
throw 'Error while tryint to authenticate to TFS server'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment