Another long title for a relatively short article.
In case you aren’t aware, the az cli has a great extension for Azure DevOps and supports automatically logging you in to the devops extension when you use az login. Very helpful and simple, no need to manually issue a PAT through the Azure DevOps portal.
Now, what about the scenario when you need a PAT to make a rest call to Azure DevOps? There are some scenarios that the devops az cli extension does not cover (such as queuing a yaml pipeline with parameters).
Here is a quick and easy PowerShell script to get you a PAT:
Note that there is not much documentation on using this mechanism with the az cli. I was able to work this out due to my previous experience obtaining an Azure Databricks token using the same command.
This is about as close as I can find to anything official: https://github.com/microsoft/azure-devops-auth-samples/blob/master/PersonalAccessTokenAPIAppSample/app_config.py