ADDING AZURE AD SECURITY GROUP TO POWER BI WORKSPACE USING POWERSHELL

ADDING AZURE AD SECURITY GROUP TO POWER BI WORKSPACE USING POWERSHELL

In this post, we will discuss how to add an AD Security group to Power BI Workspace using PowerShell script.

If you have many users in your organization, it can be tedious to add users one by one as members or Admins to a Power BI Workspace.

With PowerShell, you can add an AD group to Power BI Workspace using the Groups – Add Group User API or Add-PowerBIWorkspaceUser Cmdlet.

What you will need:

  • Object ID for the group
    • From Azure Active Directory -> Select Groups -> Select the required Group -> Copy the Object ID
  • Access right to the Workspace for the group
    • Level of Access you want to grant to the Workspace (
      Member, Admin, Contributor, Viewer )
  • The PrincipalType
    • The type of Principal you want to add (
      App, Group, User ) For this example, we want to add an AD Security Group, so we will use Group
  • The Workspace ID
    • From Power BI Service -> Select the Workspace -> copy the ID next to Group in the URL

Let’s go through the process:

Before adding the group, I have 2 permissions to the Workspace.

  • Install the following PowerShell modules
  1. Install-Module -Name MicrosoftPowerBIMgmt
  2. Install-Module -Name MicrosoftPowerBIMgmt.Workspaces
  • Add the Group Object ID, the Workspace ID and run the following script in PowerShell

Login-PowerBI

#Using AD Security group

$Body = @{
identifier= “add your Odject ID here” #Object ID for the Security group
groupUserAccessRight= “Admin” #Permission for the group to the Workspace
principalType= “Group” #The type of Principal(App, Group, User)
}

$BodyJSON=$Body | ConvertTo-Json
Invoke-PowerBIRestMethod -Method post -Url “/groups/Add your group Id here/users” -Body $BodyJSON #Workspace ID

After running the Script, the group TestGroup will be automatically added to the Workspace with the level of permission specify as seeing below:

Now all users in the group will have the same access to the Workspace without adding them individually.

Happy Scripting 🙂

Comments are closed.