LoginSignup
5
6

More than 3 years have passed since last update.

PowerShell で Microsoft Graph を実行する

Last updated at Posted at 2020-01-06

前提

  • AzureAD にアプリが登録されていること
  • 登録されたアプリに Microsoft Graph のアクセス許可が適宜設定されていること
  • AzureAD アプリの情報を取得済みであること
    • テナントID(下記の形式の内、どちらか一方)
      • contoso.onmicrosoft.com 形式
      • GUID 形式
    • クライアントID
    • クライアントシークレット

ユーザー一覧を取得する PowerShell コード

Connect-PnPOnline -AppId '<クライアントID>' -AppSecret '<クライアントシークレット>' -AADDomain '<テナントID>'
$token = Get-PnPAccessToken
$url = "https://graph.microsoft.com/v1.0/users"
$headerParams = @{'Authorization'="Bearer $token"}
$contentType = "application/json"
$response = Invoke-RestMethod -uri $url -Method Get -header $headerParams -ContentType $contentType
$response.value | Export-Csv -Path .\users.csv -Encoding UTF8 -NoTypeInformation

参考記事

PowerShell コードを書く際、こちらの記事を大変参考にさせていただきました。ありがとうございます。
PowerShell を使ってMicrosoft Teams のいいね一覧をCSV形式で出力する

参照

Connect to the Microsoft Graph using Application Permissions

5
6
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
5
6