This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
If timeouts occur when using 'expand', consider utilizing other existing APIs to acquire the required information. For instance, admins can use GetGroupUsersAsAdmin or PostWorkspaceInfo (with the 'getArtifactUsers' option) instead of expanding for users.
Similarly, admins can use artifact specific APIs to query artifacts of specific types instead of using ‘expand’ to get artifacts in a workspace. Examples of artifact specific APIs are GetReportsAsAdmin, GetDashboardsAsAdmin, GetDataflowsAsAdmin and GetDatasetsAsAdmin, which now include the 'workspaceId' property to relate the artifact to a specific workspace returned by GetGroupsAsAdmin.
However, workbooks don’t have an artifact specific API to query from workspaces. So, it’s OK to use “expand” option to get all workbooks in a workspace.
Example:
https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100&$expand=workbooks
Querying workspaces and artifacts in large tenants with thousands of workspaces and each having hundreds or thousands of artifacts can lead to lengthy query time resulting in timeouts. If such timeouts occur, try limiting the number of workspaces using the 'top' parameter.
Though the official documentation for GetGroupsAsAdmin specifies the max value allowed for 'top' parameter as 5000, users should critically think about the number of workspaces to be retrieved for a given use-case.
Example:
https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100
Syntax:
$filter=specificFilter eq 'Value'
Retrieve first 100 workspaces of type “Workspace” using 'top' and 'type' filters:
https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100&$filter=type eq ‘Workspace’
https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100&$filter=isOnDedicatedCapacity eq true
https://api.powerbi.com/v1.0/myorg/admin/groups?$top=1&$filter=name eq ‘Sales Workspace’
https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100&$filter=state eq ‘Active’ and type eq ‘Workspace’ and isOnDedicatedCapacity eq true
https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100&$expand=datasets&$filter=(not datasets/any())
This method's core concept involves acquiring two distinct lists: one listing workspaces ids with datasets, using GetDatasetsAsAdmin API, and the other cataloging all workspaces through GetGroupsAsAdmin API. Subsequently, by excluding the content of the first list from the comprehensive list of all workspaces in a tenant, this approach sidesteps the utilization of expand and filter operations.
Connect-PowerBIServiceAccount$workspacesWithoutDatasets = @()
Write-Output "Fetching workspace ids with datasets..."
# TODO: remember to include the throttling limits logic for each API (groups, users, reports, datasets, ...)
$workspacesWithDatasets = (Invoke-PowerBIRestMethod -Url 'admin/datasets' -Method GET | ConvertFrom-Json).value | Where-Object { $_.workspaceId -ne $null } | ForEach-Object { $_.workspaceId }
Write-Output "Finished getting workspace ids with datasets."
Write-Output "Fetching all workspaces"
$totalWorkspaces = @()
$currentWorkspaces = @()
$top = 100 # TODO: adjust number based on your needs
$skip = 0
$iterations = 0
do
{
Write-Output "Retrieving $top workspaces."
$url = "admin/groups?`$top={0}&`$skip={1}" -f ($top), ($skip + $top * $iterations)
# TODO: remember to include the throttling limits logic for each API (groups, users, reports, datasets, ...)
$currentWorkspaces = (Invoke-PowerBIRestMethod -Url $url -Method GET | ConvertFrom-Json).value
$totalWorkspaces += $currentWorkspaces
} while($currentWorkspaces.Count -ge $top)
$totalWorkspacesCount = $totalWorkspaces.Count
Write-Output "Total workspaces count is $totalWorkspacesCount"
foreach($workspace in $totalWorkspaces)
{
if ($workspacesWithDatasets -notcontains $workspace.id) {
$workspacesWithoutDatasets += $workspace
}
}
$workspacesWithoutDatasetsCount = $workspacesWithoutDatasets.Count
Write-Output "There are $workspacesWithoutDatasetsCount workspaces without datasets."
Our goal is to ease challenges with GetGroupsAsAdmin. Your feedback helps us gauge the impact of these efforts.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.