DEV Community

Merill Fernando
Merill Fernando

Posted on • Originally published at merill.net on

2

PowerShell script to generate a report on all Power BI workspaces and groups in your Microsoft 365 tenant

Here’s a useful script I wrote the other day. This uses a few PowerShell modules to pull together information about all the Power BI workspaces in your Microsoft 365 tenant. This also includes the names of the Workspace/Group owners.

#Install-Module AzureAD
#Install-Module MicrosoftPowerBIMgmt
#Connect-PowerBIServiceAccount
#Connect-AzureAD

$workspaces = Get-PowerBIWorkspace -Scope Organization -All
$wslist = @()
foreach ($ws in $workspaces) {
    $ws
    $owners = $null
    if ($ws.State -eq 'Active') { 
        if ($ws.Type -eq 'Workspace') {
            $u = $ws.Users | Where-Object AccessRight -eq 'Admin' | Select-Object UserPrincipalName
            Write-Host $u
            $owners = $u.UserPrincipalName -join ","
        }
        elseif ($ws.Type -eq 'Group') {
            $go = Get-AzureADGroupOwner -ObjectId $ws.ID 
            $owners = $go.UserPrincipalName -join "," 
        }
    } 
    $item = [ordered] @{
        Id = $ws.ID
        Name = $ws.Name
        Type = $ws.Type
        State = $ws.State
        IsReadOnly = $ws.IsReadOnly
        IsOrphaned = $ws.IsOrphaned
        IsOnDedicatedCapacity = $ws.IsOnDedicatedCapacity
        CapacityId = $ws.CapacityId
        Owners = $owners
    }
    $u = new-object PSObject -Property $item
    $wslist += $u
}
$wslist | Export-Csv .\PowerBI-Workspaces.csv -NoTypeInformation

Enter fullscreen mode Exit fullscreen mode

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more