よく忘れるので。
$adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" $adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" [System.Reflection.Assembly]::LoadFrom($adal) [System.Reflection.Assembly]::LoadFrom($adalforms) $adTenant = "<あなたのテナント>.onmicrosoft.com" # well-known ID $clientId = "1950a258-227b-4e31-a9cf-717495945fc2" $redirectUri = "urn:ietf:wg:oauth:2.0:oob" $resourceAppIdURI = "https://management.core.windows.net/" $authority = "https://login.windows.net/$adTenant" $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto") $authHeader = $authResult.CreateAuthorizationHeader() # Write-Host "Bearer Token: $authHeader" $authHeader | Out-File bearerToken.txt
これでBearerトークン出来上がり。認証はいつもの認証ダイアログ的なのが出るので安心です。
(要Azure PowerShell)
ピンバック: PowerShellでAzure ADの情報を収集 – Always on the clock