I wanted to share how I successfully connected to the Azure DevOps API using a Personal Access Token (PAT) from a PowerShell script. While this might be a bit late, I hope it helps others who come across this.
First, you'll need to have a PAT created in your Azure DevOps account
Now, here's the PowerShell script :
# Define your Personal Access Token (PAT)
$pat = "YOUR_PERSONAL_ACCESS_TOKEN"
# Define the DevOps API URL
$jsonUrl = "YOUR_JSON_URL_HERE"
# Create headers with the PAT for authentication
$headers = @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
}
# Make the request with authentication headers
$jsonContent = Invoke-RestMethod -Uri $jsonUrl -Headers $headers