Skip to content

Instantly share code, notes, and snippets.

@win2000b
Last active July 23, 2022 20:15
Show Gist options
  • Save win2000b/f563ea1fb538c2a5303ef4484102644c to your computer and use it in GitHub Desktop.
Save win2000b/f563ea1fb538c2a5303ef4484102644c to your computer and use it in GitHub Desktop.
PowerBI Collects all server info for workspaces and datasets
# Install PowerBI PowerShell if needed.
Install-Module -Name MicrosoftPowerBIMgmt
# Connect to PowerBI Service In PowerShell
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
if ($source)
{
$GetURL = "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($dataset.id)/datasources"
$json = Invoke-PowerBIRestMethod -Url $GetURL -Method GET
$jsonobject = ConvertFrom-Json -InputObject $json
$props=[ordered]@{
"WorkSpaceName"=$workspace.Name;
"WorkSpaceID"=$workspace.Id;
"DatasetName"=$dataset.Name;
"DatasetID"=$dataset.Id;
"Gateway"=$source.gatewayid;
"source"=$source.datasourceid;
"Datasource Type"=$jsonobject.value.Datasourcetype;
"server"=$jsonobject.value.connectiondetails.server;
"database"=$jsonobject.value.connectiondetails.database;
}
$obj=New-Object -TypeName psobject -Property $props
Export-Csv -path "c:\temp\datasettest3.csv" -InputObject $obj -Append -NoTypeInformation
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment