Getting an access token for AzureAD using PowerShell and device login flow

Intro Have you ever wanted to query an API that uses access tokens from Azure Active Directory (AzureAD) from a PowerShell script? There are a lot of solutions for this that uses an application in AzureAD and authenticates using its client-id and secret. If I have a web application or a non-interactive service this is the way to go. My friend and colleague Emanuel Palm wrote a great post on Microsoft Graph API with PowerShell for that scenario.