1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AzurePowershell で AccessToken を取得する方法

Posted at

AzurePowershell を最新化したら Azure REST API を叩くスクリプトが動かなくなった。
調べてみたら、Az.Accounts の動作変更により、従来の Get-AzContext からアクセストークンを取得する方法が使えなくなった模様。。。
新しく Get-AzAccessToken が追加されたので、今後、アクセストークンを取得する際はそれを使ってくれとのことらしい。

従来の方法

Connect-AzAccount
$context = Get-AzContext
$currentToken = $context.TokenCache.ReadItems() | Where-Object {$_.TenantId -eq $context.Tenant.Id}
$currentToken[0].AccessToken

Get-AzAccessToken を使用した方法(AzurePowershell v5.1.0 以降)

Connect-AzAccount
$context = Get-AzContext
$currentToken = Get-AzAccessToken | Where-Object {$_.TenantId -eq $context.Tenant.Id}
$currentToken[0].Token

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?