PowerShell 7.3 - guide with Retrieving and Authenticating Azure DevOps REST API Data Using PAT Token
I'm relatively new to this, so bear with me... I'm trying to access Azure DevOps REST APIs using PowerShell 7.3, and I'm running into issues with authentication when using a Personal Access Token (PAT). I've created the PAT with the required scopes, and I'm trying to make a GET request to retrieve a list of projects, but I'm receiving a `401 Unauthorized` behavior. Here's the code I've been using: ```powershell $pat = 'YOUR_PERSONAL_ACCESS_TOKEN' $organization = 'YOUR_ORG_NAME' $url = "https://dev.azure.com/$organization/_apis/projects?api-version=7.1-preview.1" $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")) $response = Invoke-RestMethod -Uri $url -Method Get -Headers @{Authorization = "Basic $base64AuthInfo"} $response ``` I've confirmed my PAT is correct and has the necessary permissions, but the `401` behavior continues. I've also tried using `Invoke-WebRequest`, but I encounter the same behavior. Is there something I'm missing in the headers or the way I'm constructing the request? Any advice on troubleshooting this scenario would be greatly appreciated! I'm working on a web app that needs to handle this. How would you solve this? Am I missing something obvious?