Retrieving list of users for all workspaces in your PowerBI tenant using Powershell

From previous blogpost(s):

Determining and checking who has access to a particular workspace in your organisation can be time consuming task. You can always retrieve the list of workspaces and access the list of all users with PowerShell cmdlet Get-PowerBIWorkspace.

The results of this cmdlet gives you a great way to get to valuable information easy and fast. And the following script can do just that.

# 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 users for each workspace (and exclude Personal Workspaces)
$WorkSpace_Users | ForEach-Object {
    $Workspace = $_.name
    foreach ($User in $_.Users) {
        [PSCustomObject]@{
            WorkspaceName = $Workspace
            UserName   =$user.Identifier
            AccessPermission = $User.accessright    
                                           }
            }
} | Select UserName, AccessPermission, WorkspaceName |  Where-Object {$Workspace -NotLike "PersonalWorkspace *"}

I have excluded the Personal Workspaces.

In addition, there is a little R script, that can be used to visualize the this tiny network 🙂

First, export the results of a Powershell script into a CSV file. Simply add the following command at the end of the script:

 |  Export-Csv "C:\DataTK\results.csv"

The R script will transform the results into Edges and Nodes. To make this script shorter, I have joined everything in nodes and added the group to set apart the users and workspaces.

library(tidygraph)
library(igraph)
library(dplyr)

file = "C:\\DataTK\\results.csv"
pbi <- read.csv(file, sep = ",", header = TRUE, skip=1)

# Data preparation
links <- pbi[,c("UserName","WorkspaceName")]
colnames(links) <- c("from","to")

# Nodes 
nodes1 <-  pbi %>% group_by(WorkspaceName) %>% summarise(n = n())
nodes1$group <- "WS"
colnames(nodes1) <- c("id","size", "group")
nodes2 <-  pbi %>% group_by(UserName) %>% summarise(n = n())
nodes2$group <- "US"
colnames(nodes2) <- c("id","size","group")
nodes <- rbind(nodes1, nodes2)

# create plot
net <- graph_from_data_frame(d=links, vertices=nodes, directed=TRUE) 
plot(net, edge.arrow.size=.5,vertex.label=V(net)$group)
Simple network of users and workspaces

Follow for more Powershell Scripts for Power BI on Github.

Happy scripting and stay healthy!

Tagged with: , , , , ,
Posted in Power BI, Uncategorized
One comment on “Retrieving list of users for all workspaces in your PowerBI tenant using Powershell
  1. […] Retrieving list of users for all workspaces in your PowerBI tenant using Powershell […]

    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 ...