Forum Discussion
Anonymous
5 years agoNot applicable
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 ...
- 5 years ago
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.
v-lionel-msft
Community Support
5 years agoHi 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 Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
5 years agoNot 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
}
}
}
$DataSets
bear in mind, i am a beginner
cheers