1
2

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 5 years have passed since last update.

貼って使う Azure CLI スニペット(Azure Active Directory編)

Posted at

概要

  • Azure リソースのメンテナンス等で使えそうなコマンドのスニペット(PowerShell ベース)をまとめました
  • PowerShell コンソールに貼って使えます
  • 今回は Azure Active Directory に関するスニペットをまとめます

前提

  • Azure CLI がインストールされている前提です
  • 実行するには、事前に az login コマンドで 認証する必要があります(参考:Azure CLI の概要 - サインイン
  • 環境情報:
    • Azure CLI(v.2.0.57)
    • PowerShell(v.5.1.17134.407)
  • 安全に試せるよう 情報取得系 中心にまとめます(一部注意事項あります)
  • 一部のスニペットは実行時にパラメータが必要となります

自分(現在サインインしているユーザ)の情報を取得したい

az ad signed-in-user show

ユーザ の一覧を取得したい

az ad user list

グループ の一覧を取得したい

az ad group list

ユーザ or グループ の名称(表示名)一覧を取得したい

  • ユーザ
(az ad user list | ConvertFrom-Json) | % {$_.displayName}
  • グループ
(az ad group list | ConvertFrom-Json) | % {$_.displayName}

ユーザ表示名 と オブジェクトIDを一覧表示したい

  • 今回は一覧表示させるために Out-GridView を使用。GUI環境で一覧データを扱うのに便利。
(az ad user list | ConvertFrom-Json) | `
    select `
        @{N="表示名"; E={$_.displayName}}, `
        @{N="姓"; E={$_.surname}}, `
        @{N="名"; E={$_.givenName}}, `
        @{N="UPN(ログイン名)"; E={$_.userPrincipalName}}, `
        @{N="オブジェクトID"; E={$_.objectId}} `
    | Out-GridView;

アプリケーション名、オブジェクトID、アプリケーションIDを一覧表示させる

(az ad app list | ConvertFrom-Json) | `
    select `
        @{N="表示名"; E={$_.displayName}}, `
        @{N="アプリケーションID"; E={$_.appId}}, `
        @{N="オブジェクトID"; E={$_.objectId}} `
    | Out-GridView;

特定のグループに所属するメンバを一覧表示させる

Param(
    [Parameter(Mandatory=$true)] $groupName
); `
(az ad group member list -g $groupName | ConvertFrom-Json) | `
    select `
        @{N="表示名"; E={$_.displayName}}, `
        @{N="姓"; E={$_.surname}}, `
        @{N="名"; E={$_.givenName}}, `
        @{N="UPN(ログイン名)"; E={$_.userPrincipalName}}, `
        @{N="オブジェクトID"; E={$_.objectId}} `
    | Out-GridView;

自分が所属するグループ一覧を表示する

  • UPN(ログイン名) か ユーザのオブジェクトIDが必要
(az ad signed-in-user show | ConvertFrom-Json) | `
    % {(az ad user get-member-groups --upn-or-object-id $_.userPrincipalName | ConvertFrom-Json)} | `
        select `
            @{N="表示名"; E={$_.displayName}}, `
            @{N="オブジェクトID"; E={$_.objectId}} `
        | Out-GridView;

特定のユーザが所属するグループ一覧を表示する

  • UPN(ログイン名) か ユーザのオブジェクトIDが必要
Param(
    [Parameter(Mandatory=$true)] $upnOrObjectId
); `
(az ad user get-member-groups --upn-or-object-id $upnOrObjectId | ConvertFrom-Json) | `
    select `
        @{N="表示名"; E={$_.displayName}}, `
        @{N="オブジェクトID"; E={$_.objectId}} `
    | Out-GridView;
1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?