Forum Discussion
how can i list Workspace and datasets by workspace
hi all, first of all, i am a total beginner (2 days in the learning)
i am looking for a good snippet of powershell script that will present workspaces and datatsets like this.
note, multiple lines for a workspace
| Workspace A | workspace A id | Dataset x | dataset x id | |||
| Workspace A | workspace A id | Dataset y | dataset y id | |||
| Workspace B | workspace B id | Dataset z | dataset z id |
i wrote this, but it puts everything on one line
$Workspaces = Get-PowerBIWorkspace -Scope Organization -Include All -Filter "tolower(name) eq 'ci workspace'"
$WorkspacesInfo = $Workspaces | Select-Object -Property Name, Id,
@{n="Datasets";e={$_.Datasets.Name -join ', '}},
@{n="DatasetIds";e={$_.Datasets.Id -join ', '}}
$WorkspacesInfo
i would like the datasets each on their own unique line, along with the workspace they are associated with
thanks in advance
Hi Anonymous ,
You must be the Power BI Service administrator.
PBI Service admin can use "Admin portal" feature.
Best regards,
Lionel ChenIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 Replies
- v-lionel-msft
Community Support
Hi Anonymous ,
Please refer to the code.
Connect-PowerBIServiceAccount # Variable to receive the codes of the Power BI workspaces $Workspace = Get-PowerBIWorkspace -All # Loop for each workspace and for each dataset, get the data from the column below $DataSets = ForEach ($workspace in $Workspace) { Write-Host $workspace.Name ForEach ($dataset in (Get-PowerBIDataset -WorkspaceId $workspace.Id)) { [pscustomobject]@{ WorkspaceName = $Workspace.Name WorkspaceID = $workspace.Id DatasetName = $dataset.Name DatasetID = $dataset.Id } } } # Defines the directory and name of the file to be exported to the CSV file $Dir = "C:\Users\lionelch\Desktop\Sampledata\MyWorkspace.csv" # Exports the result to the CSV file in the directory informed above $DataSets | Export-Csv $Dir -NoTypeInformation -Encoding UTF8 Disconnect-PowerBIServiceAccount--My result
Best regards,
Lionel ChenIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Hi Lionel
thanks for answering my question
It does not appear to be returning records. i modified it like this too, to see on screen output but nothing.
Note, there is valid data in $Workspace, i ran it on its own in isolation and it output fine
$Workspace = Get-PowerBIWorkspace -All -Scope Organization -ErrorAction SilentlyContinue -Include All ` -Filter "tolower(state) eq 'active' and tolower(type) ne 'personalgroup' and tolower(name) eq 'hexit'" ` | Select-Object Id, Name, Type, State, Description, IsOrphaned # Loop for each workspace and for each dataset, get the data from the column below $DataSets = ForEach ($workspace in $Workspace) { Write-Host $workspace.Name ForEach ($dataset in (Get-PowerBIDataset -WorkspaceId $workspace.Id)) { [pscustomobject]@{ WorkspaceName = $Workspace.Name WorkspaceID = $workspace.Id DatasetName = $dataset.Name DatasetID = $dataset.Id } } } $DataSetsbear in mind, i am a beginner
cheers
- AnonymousNot applicable
hi Lionel
could it be because i am running this with -Scope Organization. When running the Get-PowerBIDataset manually i get an error
Get-PowerBIDataset -Scope Organization -WorkspaceId 75036789-685c-40b9-9034-4c4386d8bd1d -Debug DEBUG: 13:01:40 - Get-PowerBIDataset begin processing with ParameterSet List. DEBUG: 13:01:41 - Cmdlet version: 1.0.896.0 Get-PowerBIDataset : A task was canceled. At line:1 char:1 + Get-PowerBIDataset -Scope Organization -WorkspaceId 75036789-685c-40b ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (Microsoft.Power...tPowerBIDataset:GetPowerBIDataset) [Get-PowerBIDataset], TaskCanceledException + FullyQualifiedErrorId : A task was canceled.,Microsoft.PowerBI.Commands.Data.GetPowerBIDataset VERBOSE: Request Uri: https://api.powerbi.com/v1.0/myorg/admin/groups/75036789-685c-40b9-9034-4c4386d8bd1d/datasets VERBOSE: Status Code: 429 (429) VERBOSE: Request Uri: https://api.powerbi.com/v1.0/myorg/admin/groups/75036789-685c-40b9-9034-4c4386d8bd1d/datasets VERBOSE: Status Code: 429 (429) DEBUG: 13:03:28 - Get-PowerBIDataset end processing. - cateoRegular Visitor
Hi Lionel,
This works for me, but only for workspaces which have datasets in them.
Is it possible to get a list of all workspaces, even though they have no datasets yet?
Thank you in advance!
- v-lionel-msft
Community Support
Hi Anonymous ,
You must be the Power BI Service administrator.
PBI Service admin can use "Admin portal" feature.
Best regards,
Lionel ChenIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.