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"

Leave a Reply