---
title: "Explore TFS API with TFS PowerShell Examples"
description: "Manage TFS and dive into its API using practical TFS PowerShell examples."
canonical: "https://adamtheautomator.com/tfs-powershell-examples/"
---

# Explore TFS API with TFS PowerShell Examples

> Manage TFS and dive into its API using practical TFS PowerShell examples.

Source: https://adamtheautomator.com/tfs-powershell-examples/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Explore TFS API with TFS PowerShell Examples](https://adamtheautomator.com/wp-content/uploads/2019/08/devops-3155973_1280.jpg)

# Explore TFS API with TFS PowerShell Examples

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)8 August 20192 min. read

Categories: [Software Development](/category/software-development/)

Tags:[Microsoft Team Foundation Server](/tag/microsoft-team-foundation-server/)[PowerShell](/tag/powershell/)

Table of Contents

*   [Authenticating to TFS](#getting-started)
*   [TFS PowerShell Example with Invoke-RestMethod](#h-querying-the-tfs-powershell-example)
*   [Next Steps](#summary)

If you’re using Microsoft’s Team Foundation Server (TFS) and you need to manage it with PowerShell, this post is for you. In this tutorial, you’re going to learn with TFS PowerShell examples, how to manage TFS. You never know, you might just want to take this knowledge and build a TFS PowerShell module from it!

TFS provides a rich API that can be used in conjunction with PowerShell to build a handy way to control TFS with the command line and via PowerShell script.

In this article, we’re going to cover the basics of what it takes to make that initial connection to TFS with PowerShell. The code you’ll be using can then be used to explore more API operations with PowerShell to build more advanced functionality.

## Authenticating to TFS

To access the TFS REST API , you’ll first need to authenticate. In this TFS PowerShell example, use a _PSCredential_ object. To create a _PSCredential_ object, run `Get-Credential` and provide an account that has access to TFS

```powershell
PS51> $credential = Get-Credential
```

Related:[Using the PowerShell Get-Credential Cmdlet and All Things Credentials](https://adamtheautomator.com/powershell-get-credential/)

Once you have a credential saved as a variable, then use this throughout numerous calls to the PowerShell cmdlet `Invoke-RestMethod`.

`Invoke-RestMethod` is a PowerShell cmdlet that allows us to craft and send various HTTP requests to REST APIs quickly. Since I’ll need to use the `Credential` parameter for each `Invoke-RestMethod` call, I’ll create a splatted parameter set with `Credential` inside so I don’t have to specify it every time.

```powershell
$invRestMethParams = @{
    Credential = $credential
}
```

## TFS PowerShell Example with Invoke-RestMethod

Now send a test query to TFS just to ensure you don’t receive an error. Try to retrieve all of the projects available to you on the server. You can do this by sending the HTTP GET method to the API. But first, you need to know the URI. To retrieve all of the projects, the URL scheme will look like this:

_http(s)://<TFSServer>/<TeamCollection>/<TeamProject>/\_apis/projects?api-version=2.0_

You can see that I’m using v2.0 of the API. My particular URI looks like this:

```powershell
$uri = 'http://tfs.domain.local:8080/tfs/IT/_apis/projects?api-version=2.0'
```

Now that you know the URI, you can then add this to the parameters to `Invoke-RestMethod`.

```powershell
PS51> $invRestMethParams.Uri = $uri
```

Next, I’ll need to add the other parameters to `Invoke-RestMethod`.

Related:[How to Work with REST APIs and PowerShell’s Invoke-RestMethod](https://adamtheautomator.com/invoke-restmethod/)

```powershell
$invRestMethParams.Method = 'Get'
$invRestMethParams.ContentType = 'application/json'

## My final parameters and the Invoke-RestMethod call will look like this:

$invRestMethParams = @{
    Credential = $credential
    Uri = $uri
    Method = 'Get'
    ContentType = 'application/json'
}
Invoke-RestMethod @invRestMethParams
```

When I run the above code, you’ll get an output that looks like this. This TFS PowerShell example uses `Invoke-RestMethod` to initiate an API request.

![Finding TFS projects with PowerShell](/wp-content/uploads/2019/08/Picture1-27.png)

Finding TFS projects with PowerShell

This isn’t too helpful. To get at what you’re looking for, you need to look at the contents of the `value` property. You’ll immediately see once you look at the value property, each of the projects inside of the collection will show up.

![Drilling down on TFS projects](/wp-content/uploads/2019/08/Picture1-28.png)

Drilling down on TFS projects

This means that you’ve authenticated to TFS and have queried the correct URI.

At this point, the world is your oyster. Perhaps you’d like to see all of the builds available to you. Because I’ve stored all of the parameters inside of the hashtable, I just have to change the `Uri` parameter. You could use the below TFS PowerShell example.

```powershell
$invRestMethParams.Uri = 'http://tfs.domain.local:8080/tfs/IT/IS-DevOps/_apis/build/builds?api-version=2.0'
```

![Finding TFS builds with PowerShell](/wp-content/uploads/2019/08/Picture1-29.png)

Finding TFS builds with PowerShell

You can see that after you get authenticated and figure out the correct URL scheme, it’s just a matter of changing up the URL to do what you want. To learn a lot more about what you can do with the TFS REST API, I encourage you to check out the [Visual Studio getting started documentation](https://docs.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-7.1&viewFallbackFrom=azure-devops).

## Next Steps

Using PowerShell, you can begin managing and automating many things with TFS. Managing TFS with PowerShell allows you to integrate various TFS processes into concepts like a CI/CD pipeline among other things.

Now take what you’ve learned and see if you can improve upon it by creating a TFS PowerShell module!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Ftfs-powershell-examples%2F&text=Explore%20TFS%20API%20with%20TFS%20PowerShell%20Examples)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Ftfs-powershell-examples%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Ftfs-powershell-examples%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/08/26572_featured_image.webp)

### [PowerShell Control Flow: A Practical Guide to Conditional Logic](/powershell-control-flow-guide/)

Learn how to use PowerShell control flow including if statements, switch statements and conditional logic with practical real-world examples for server administration.

![](https://adamtheautomator.com/wp-content/uploads/2025/04/featured-image.png)

### [Vibe Coding: How I Built a 120K Line App Without “Learning to Code”](/vibe-coding-with-ai/)

Building real applications with AI isn't just for developers anymore. Here's how I went from PowerShell scripts to a full-stack React/Express app by embracing "vibe coding" with AI.

![](https://adamtheautomator.com/wp-content/uploads/2021/03/git-checkout-remote-branch.jpg)

### [Easily Perform Git Checkout Remote Branch \[Step-by-Step\]](/git-checkout-remote-branch/)

Learn how Git remote branches work, effectively track remotes, and best practices to manage remotes and branches.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
