Retrieving user access list to all reports in your PowerBI tenant using Powershell

From previous blogpost(s):

Ever wanted to get the list of all users and their access to reports? The snippet below will return you just that. The list of:

  • User Name
  • Report Name
  • Workspace Name
  • Access level

This way, you will have a better view of users, and their access to data and reports (if these are containing sensible data). You can always retrieve the list of workspaces and access the list of all users with the PowerShell cmdlet Get-PowerBIWorkspace.

I have also added the Join-Object module. It can join two objects or two arrays, based on the given matching columns.

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 
Import-Module Join-Object

# 1. Login to app.power.bi
$user = "YourAzure.Email@domain.com"
$pass = "YourStrongP422w!!rd"

$SecPasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$myCred = New-Object System.Management.Automation.PSCredential($user,$SecPasswd)
Connect-PowerBIServiceAccount -Credential $myCred

# 2. Get list of users and workspaces
$WorkSpace_Users = Get-PowerBIWorkspace -Scope Organization -Include All -All


# 3. Iterate through the workspace and get reports in each workspace (exclude Personal Workspaces)
$reposts_WS = $WorkSpace_Users | ForEach-Object {
            $Workspace = $_.name
            foreach ($Rep in $_.Reports) {
                [PSCustomObject]@{
                    WorkspaceName = $Workspace
                    ReportID = $Rep.id
                    ReportName   =$Rep.Name}
                    }
        } | Select ReportID, ReportName, WorkspaceName |  Where-Object {$Workspace -NotLike "PersonalWorkspace *"} 


# 4. Iterate through the workspace and get users with access policy on each workspace (exclude Personal Workspaces)
$users_WS =  $WorkSpace_Users | ForEach-Object {
            $Workspace = $_.name
            foreach ($User in $_.Users) {
                [PSCustomObject]@{
                    WorkspaceName = $Workspace
                    AccessPermission = $User.accessright    
                    UserName   =$user.Identifier}
                    }
        } | Select UserName, AccessPermission, WorkspaceName |  Where-Object {$Workspace -NotLike "PersonalWorkspace *"}  


# 5. Merge two data
$joinedWS = Join-Object -Left $reposts_WS -Right $users_WS -LeftJoinProperty 'WorkspaceName' -RightJoinProperty 'WorkspaceName'  -Type OnlyIfInBoth -LeftProperties ReportName, WorkspaceName  -RightProperties UserName, AccessPermission

Same as in the previous example, I have excluded the Personal Workspaces.

Follow for more Powershell Scripts for Power BI on Github.

Happy scripting and stay healthy!

Tagged with: , , , , , ,
Posted in Power BI, Uncategorized
6 comments on “Retrieving user access list to all reports in your PowerBI tenant using Powershell
  1. […] Tomaz Kastrun wants to know what you can see: […]

    Like

  2. shekhar says:

    join-object module was not found. How to fix it.

    Like

  3. Alyssa says:

    accespermission is empty. How to fix this?

    Like

  4. Paola A Zambrano says:

    I got the list of users per workspace, but I would like to get the list of users of each report. How would I get that done?

    Like

Leave a comment

Follow TomazTsql on WordPress.com
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (http://www.rednoses.eu/red-noses-organisations/slovenia/)

€2.00

Top SQL Server Bloggers 2018
TomazTsql

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Discover WordPress

A daily selection of the best content published on WordPress, collected for you by humans who love to read.

Revolutions

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

tenbulls.co.uk

tenbulls.co.uk - attaining enlightenment with the Microsoft Data and Cloud Platforms with a sprinkling of Open Source and supporting technologies!

SQL DBA with A Beard

He's a SQL DBA and he has a beard

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

R news and tutorials contributed by hundreds of R bloggers

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Insane Asylum (A Blog by Pat Wright)

Information about SQL (PostgreSQL & SQL Server) from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...