Skip to content

Instantly share code, notes, and snippets.

@win2000b
Created July 18, 2019 11:28
Show Gist options
  • Save win2000b/913968a4b0d6059242ddf6d1dd8db854 to your computer and use it in GitHub Desktop.
Save win2000b/913968a4b0d6059242ddf6d1dd8db854 to your computer and use it in GitHub Desktop.
Get All PowerBI Workspaces and the Datasets and What Datasource they use.
# Login to PowerBI Service
Connect-PowerBIServiceAccount
# Get all Workspaces from the Organization that start with UK.
$UKWorkspaces = Get-PowerBIWorkspace -scope Organization -all | Where-Object {$_.name -like 'uk*'}
# For Each Workspace workout the Datasets and the Datasources that correspond to them.
foreach ($workspace in $UKWorkspaces)
{
$ukdatasets = $workspace | Get-PowerBIDataset -scope Organization
foreach ($dataset in $UKdatasets)
{
$source=$dataset|Get-PowerBIDatasource -scope Organization
$props=[ordered]@{
"WorkSpaceName"=$workspace.Name;
"WorkSpaceID"=$workspace.Id;
"DatasetName"=$dataset.Name;
"DatasetID"=$dataset.Id;
"Gateway"=$source.gatewayid;
"source"=$source.datasourceid;
}
$obj=New-Object -TypeName psobject -Property $props
Export-Csv -path "c:\temp\dataset.csv" -InputObject $obj -Append -NoTypeInformation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment