As per Eduardo Aquiles, if you configure your TeamCity server to support HTTP NTLM authentication (TeamCity 8.x NTLM HTTP Authentication), you can get a session cookie (TCSESSIONID) from the /ntlmLogin.html url and use that to authenticate against the REST API.
I've just had to do something similar to get the pinned state of builds. Here's the PowerShell I used:
function Get-TeamCityNtlmAuthCookie()
{
param( [string] $serverUrl )
$url = "$serverUrl/ntlmLogin.html";
$cookies = new-object System.Net.CookieContainer;
$request = [System.Net.WebRequest]::Create($url);
$request.CookieContainer = $cookies;
$request.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;
$request.PreAuthenticate = $true;
$response = $request.GetResponse();
return $cookies;
}
function Get-TeamCityBuildPinnedState()
{
param( [string] $serverUrl, [string] $buildTypeId)
# get a session cookie to use with the rest api
$cookies = Get-TeamCityNtlmAuthCookie $serverUrl;
# query the rest api using the session cookie for authentication
$url = "$serverUrl/httpAuth/app/rest/builds/id:$buildTypeId/pin/";
$request = [System.Net.WebRequest]::Create($url);
$request.CookieContainer = $cookies;
$response = $request.GetResponse();
$stream = $response.GetResponseStream();
$reader = new-object System.IO.StreamReader($stream);
$text = $reader.ReadToEnd();
$reader.Close();
return [bool]::Parse($text);
}
$myServerUrl = "http://myTeamCityServer";
$myBuildId = "6";
$pinned = Get-TeamCityBuildPinnedState $myServerUrl $myBuildId;
write-host $pinned;
Note: I'm not sure if this is officially supported by JetBrains, so you might find it breaks in a future version of TeamCity, but it currently works against version 8.0.2 (build 27482).