0
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?

PowerShell で Fabric / Power BI Workspace の管理者一覧を CSV 出力する

0
Posted at

概要

この PowerShell スクリプトは、Microsoft Fabric / Power BI の Workspace 一覧を取得し、各 Workspace に設定されているユーザー・グループ・Service Principal のアクセス権限を CSV に出力します。

Workspace の管理者だけを確認したい場合は、-AdminOnly を付けて実行します。

サンプルコード

今回利用する PowerShell スクリプトは、以下の GitHub リポジトリに配置しています。

ExportWorkspaceAccessLists.ps1

このスクリプトでは、Fabric Admin API を利用して Workspace 一覧を取得し、各 Workspace に付与されているユーザー・グループ・Service Principal のアクセス権限を CSV として出力します。

できること

  • Fabric / Power BI Workspace の一覧を取得
  • 各 Workspace のアクセス権限を取得
  • Workspace Admin のみを抽出
  • Personal Workspace を除外
  • Capacity ID で対象 Workspace を絞り込み
  • 結果を CSV に出力
  • 失敗した Workspace はエラー CSV に出力

前提条件

  • PowerShell が利用できること
  • Az.Accounts モジュールがインストールされていること
  • 実行ユーザーに Fabric Admin API を呼び出す権限があること

Az.Accounts が未導入の場合は、以下でインストールします。

Install-Module Az.Accounts -Scope CurrentUser

スクリプト名

ExportWorkspaceAccessLists.ps1

主なパラメーター

パラメーター 説明
-ExcludePersonalWorkspaces Personal Workspace を除外
-CapacityId 指定した Capacity 配下の Workspace のみ対象
-AdminOnly Workspace Role が Admin の行のみ出力
-OutputPath 通常結果の CSV 出力先
-ErrorPath エラー結果の CSV 出力先
-PauseSeconds API 呼び出し間隔。既定値は 5 秒

実行方法

1. スクリプトのあるフォルダーに移動

cd "D:\Folder"

2. Capacity ID を指定して実行

.\ExportWorkspaceAccessLists.ps1 `
  -ExcludePersonalWorkspaces `
  -AdminOnly `
  -CapacityId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Capacity ID は Fabric の管理画面から確認できます。

Fabric 画面右上の歯車アイコン
→ 管理ポータル
→ 容量設定
→ 対象の Capacity を選択
→ 設定 / 歯車アイコン
→ 容量 ID を確認

3. Workspace Admin のみを出力

.\ExportWorkspaceAccessLists.ps1 `
  -ExcludePersonalWorkspaces `
  -AdminOnly `
  -OutputPath ".\workspace_admins.csv" `
  -ErrorPath ".\workspace_errors.csv"

4. API 制限を考慮してゆっくり実行

Workspace 数が多い場合は、-PauseSeconds を大きめに設定します。

.\ExportWorkspaceAccessLists.ps1 `
  -ExcludePersonalWorkspaces `
  -AdminOnly `
  -PauseSeconds 18

実行サンプル

image.png

実行後の出力

既定では、以下の CSV が作成されます。

ファイル 内容
workspace_users.csv Workspace のアクセス権限一覧
workspace_errors.csv 取得に失敗した Workspace のエラー一覧

-OutputPath-ErrorPath を指定した場合は、そのパスに出力されます。

出力サンプル

以下はマスキング済みのサンプルです。

"Workspace Name","Workspace ID","Workspace Type","Workspace State","Principal Name","Principal ID","Principal Type","User PrincipalName","Group Type","Access Type","Workspace Role"
"dev-workspace1","xxxxxxxx-xxxx-xxxx-xxxx-000000000001","Workspace","Active","System Administrator","xxxxxxxx-xxxx-xxxx-xxxx-111111111111","User","admin@example.onmicrosoft.com","","Workspace","Admin"
"test-workspace1","xxxxxxxx-xxxx-xxxx-xxxx-000000000002","Workspace","Active","System Administrator","xxxxxxxx-xxxx-xxxx-xxxx-111111111111","User","admin@example.onmicrosoft.com","","Workspace","Admin"
"prod-workspace1","xxxxxxxx-xxxx-xxxx-xxxx-000000000003","Workspace","Active","User A","xxxxxxxx-xxxx-xxxx-xxxx-222222222222","User","user01@example.onmicrosoft.com","","Workspace","Admin"
"analytics-workspace","xxxxxxxx-xxxx-xxxx-xxxx-000000000004","Workspace","Active","System Administrator","xxxxxxxx-xxxx-xxxx-xxxx-111111111111","User","admin@example.onmicrosoft.com","","Workspace","Admin"

補足

-AdminOnly を付けない場合、Admin だけでなく Member、Contributor、Viewer などのロールも出力されます。

グループが Workspace Admin として設定されている場合、このスクリプトではグループ名が出力されます。グループのメンバーを展開する場合は、別途 Microsoft Graph API でグループメンバーを取得する必要があります。

0
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
0
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?