Here is the next article about how to manage your Power BI Services object using Powershell ! In this article we will see how to retrieve the security of all the workspaces.
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.
Pre-requisite
- Being admin of your Power BI tenant
- PowerBIMgmt Powershell module must be installed
- A “C:\temp\csv” folder must exist
Retrieve the security
The security of a workspace can be accessed using Get-PowerBIWorkspace and expanding the “Users” field.
In this “Users” field we will retrieve properties as :
- Identifier (The mail address if this is a user, an ID if it is a group)
- AccessRight (Viewer, Member, Contributor, Admin)
- PrincipalType (User, Group)
Here is a small script that will create a CSV file with workspaces name, users identifier, users access right and users principal type
$securityFilePath = 'C:\temp\csv\security.csv'
Connect-PowerBIServiceAccount
$workspaces = Get-PowerBIWorkspace -Scope Organization -All -Filter "tolower(type) eq 'workspace' "
#$workspaces
'WorkspaceName;UserIdentifier;UserAccessRight;UserPrincipalType' | Out-File $securityFilePath -Append
Foreach($workspace in $workspaces){
$users = $workspace.Users
Foreach($user in $users){
$workspace.Name+';'+$user.Identifier+';'+$user.AccessRight+';'+$user.PrincipalType | Out-File $securityFilePath -Append
}
}
Disconnect-PowerBIServiceAccount
In the next article I will show you how to push the security to another workspace !