Power BI Admin Management – Workspaces !

If you are here, you have probably met a Power BI migration. I will write a serie of 6 articles about how you can manage Power BI Service objects with the PowerBIMgmt Powershell module.

This article is part of an article’s series about how to make a tenant-to-tenant migration, this is why we pass by CSV files. Doing it, we can have more control if we want to make modifications between the steps.


  • Having admin rights on the tenant where you are (not necessary to be admin of all the workspaces, we’ll a script for that later)


We are on a tenant with Power BI reports connected to SQL Server data sources (we will not treat data flows in this series but I will put the docs at the end of the article if you want informations about it).

Let’s imagine you have to migrate all the objects of your Power BI Service tenant. How can we split all the objects ?

  • Workspaces
  • Security
  • Reports
  • Datasets
  • Datasources
  • Gateway (will not be treated because we cannot use PowerBIMgmt to do it)

How can PowerBIMgmt help me ?

With this Powershell module you will be able to do a lot of things. Let’s start first with the workspaces.

FIRST OF ALL, when you use this module to query you Power BI environment you must use Connect-PowerBIServiceAccount at the beginning of your script and Disconnect-PowerBIServiceAccount at the end of your script !


This command returns informations about workspaces. It can take parameters that you can see in the offical doc

Let’s make a first script that will extract the workspaces names and their ID and put it in a CSV file in a defined folder.

$csvPath = 'C:\temp\csv'  #Folder where the CSV file will be
$workspaceFile = 'workspaces.csv'  #Name of our CSV file 

$workspaceFilePath = $csvPath + '\' + $workspaceFile

#check if csvPath doesn't exists and create the folder if needed
if (-not (Test-Path -LiteralPath $csvPath)) {
    try {
        New-Item -Path $csvPath -ItemType Directory -ErrorAction Stop | Out-Null #-Force
    catch {
        Write-Error -Message "Unable to create directory '$csvPath'. Error was: $_" -ErrorAction Stop
    "Successfully created directory '$csvPath'."

else {
    "Directory already existed"

Connect-PowerBIServiceAccount #Connect to Power BI Service

$workspaces = Get-PowerBIWorkspace -Scope Organization -Filter "tolower(type) eq 'workspace' and tolower(state) eq 'active'" #Get the workspaces (not the personal ones) that are active

'workspace;workspaceId' | Out-File $workspaceFilePath -Append #Create the header of our CSV file (the file should not exist or should be empty !)

 Foreach($workspace in $workspaces){ #Loop through all the workspaces that we received

 $workspace #Display informations about the current workspace on the screen

 $workspace.Name + ';' + $workspace.Id | Out-File $workspaceFilePath -Append #Put the workspaces names and ids in our CSV file


Disconnect-PowerBIServiceAccount #Disconnect from Power BI Service

This Powershell script will create a “workspaces.csv” file in your “C:\temp\csv” folder.

Okay, cool, but now how am I supposed to automatically create them in my new tenant ?!

Now we will use New-PowerBIWorkspace

Let’s loop through our “workspaces.csv” file and create a new workspace for each line.

$filePath = 'C:\temp\csv\workspaces.csv' #Location of our workspaces.csv file

$workspacesCSV = Import-Csv -Path $filePath -Delimiter ';' #Import as CSV in $workspacesCSV

Connect-PowerBIServiceAccount #Connect to Power BI Service

Foreach($row in $workspacesCSV){ #Loop through $workspacesCSV
    $currentWorkspace = $row.workspace #Get the name of the workspace, row by row 

    New-PowerBIWorkspace -Name $currentWorkspace #Create the new workspace with the current row name


Disconnect-PowerBIServiceAccount #Disconnect from Power BI Service

At this point, all the workspaces are created on the new tenant. Obviously they are still empty and have no security (you are admin of all of them).

Wow it’s like some black magic !

In the future you will need their new IDs so let’s make a script to get their IDs again and put them in a CSV file called “new_workspaces.csv”. This script will be executed on the new tenant.

$csvPath = 'C:\temp\csv' #CSV folder
$workspaceFile = 'new_workspaces.csv' #Filename for the new_workspaces CSV file

$workspaceFilePath = $csvPath + '\' + $workspaceFile #Full path to the CSV file

Connect-PowerBIServiceAccount #Connect to Power BI Service

$workspaces = Get-PowerBIWorkspace -Scope Organization -Filter "tolower(type) eq 'workspace' " #Get workspaces (not the personal ones)

'workspaceName;workspaceId' | Out-File $workspaceFilePath -Append #Create the header of our CSV file
 Foreach($workspace in $workspaces){ #Loop through workspaces
 $workspace.Name + ';' + $workspace.Id | Out-File $workspaceFilePath -Append #Create a line in the CSV file for each workspace


Disconnect-PowerBIServiceAccount #Disconnect from Power BI Service

This is the end of this article, you have successfully created the workspaces of a tenant to another one !

In the next article we will talk about the workspace security.

Thank you all for reading me

PowerBIMgmt documentation – https://learn.microsoft.com/en-us/powershell/power-bi/overview?view=powerbi-ps