Custom Scripts – Power Shell

One of my close friend had this discussion with me about how to get list of workspaces with certain conditions and how to get those details using PowerShell script. So this following script was written to get conditional workspaces and displaying them.

While we were testing this, we realized that there was an error thrown due to number of calls the script was making. To handle that we can add start – stop as a gap timer to this to ensure there is no issue.

$worksapces = Get-PowerBIWorkspace -Scope Organization -All

Write-Host "Getting Workspaces"

$groupnames = @()

ForEach ($workspace in $worksapces) 
{if ($workspace.Type -eq "PersonalGroup") { continue }
if ($workspace.IsOnDedicatedCapacity) { continue }

$reports = Get-PowerBIReport -WorkspaceId $workspace.Id  -Scope Organization

if ($reports.Length -eq 0) { continue }

if ($reports.Length -gt 0) {
    Write-Host "$($workspace.Name) - $($workspace.Type) - $($workspace.State) - $($workspace.IsOnDedicatedCapacity) - $($reports.Count)"

$exportWS = New-Object -TypeName PSObject -Property @{
    Name = $workspace.Name
    Type = $workspace.Type
    State = $workspace.State
    IsOnDedicatedCapacity = $workspace.IsOnDedicatedCapacity
    ReportCount = $reports.Count
$groupnames += $exportWS
$groupnames | Export-CSV "you_chosen_path_entire_path_is_needed.csv"

Published by Ansh Purohit

I am a data enthusiast and enjoy working with data manipulation tools and languages. Power BI is my passion and I consider myself a life long learner. I enjoy sharing my knowledge with others because I firmly believe that Knowledge Increases by Sharing.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: