Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello Power BI Admins, I have a requirment to produce a list of all the connections configured on the On-Premise or Enterprise Gateway. I did not find anything online so posting question here.
is it possible to extract a list with details:
1. list of data source (Connection name, source type, server/dbname or linketc, Authentication type).
2. list of users having access to each connection.
Solved! Go to Solution.
Hi @Anonymous,
After research, there is no such list including data source and users. You need to produce them one by one.
Best Regards,
Angelia
You can use following hard coded Powershell script on your local system provided that you have Power BI admin access role in your organization:
1) Open Notepad and copy-Paste following Powershell script and save as Datasourcedetails.PS1 on your Local system path For example: C:\Users\Datasourcedetails.PS1
2) Open Powershell, Change Directory to C:\Users\ folder and run command .\Datasourcedetails.PS1 and it will take you to browser window to authenticate.
#========================================================================
# This PowerShell Script creates 2 Files
# 1) GatewayDataSources.csv: Lists all data source on On-Premises Gateways for all Gateway IDs mentioned in $gatewayIds = @("","") function
# 2) DatasourceUsers.csv: Lists users of all Data sources on On-Premises Gateways for all Gateway IDs mentioned in $gatewayIds = @("","") function.
# Author: Amit J
#========================================================================
# Part 1 : Lists all data source on On-Premises Gateways for all Gateway IDs mentioned in $gatewayIds = @("","") function
# Install the necessary module if not already installed
if (-not (Get-Module -ListAvailable -Name MicrosoftPowerBIMgmt)) {
Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser
}
# Import the module
Import-Module -Name MicrosoftPowerBIMgmt
# Log in to Power BI
Login-PowerBI
# Define the gateway IDs, you can define multiple gateway ID or gateway cluster ID if you have multiple gateways
$gatewayIds = @("Enter your gateway ID 1 or gateway cluster ID 1 here", "Enter your gateway ID 2 or gateway cluster ID 2 here")
# Function to get data sources for a specific gateway
function Get-GatewayDataSources {
param (
[string]$gatewayId
)
# Construct the full API URL for the gateway
$url = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId/datasources"
Write-Output $url
# Make the API request
$response = Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json
return $response.value
}
# Function to get gateway name
function Get-GatewayName {
param (
[string]$gatewayId
)
# Construct the full API URL for the gateway
$url = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId"
# Make the API request
$response = Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json
return $response.name
}
# Initialize an array to store all data sources
$dataSourcesList = @()
# Loop through each gateway ID and get the data sources
foreach ($gatewayId in $gatewayIds) {
$gatewayName = Get-GatewayName -gatewayId $gatewayId
# Display progress
Write-Progress -Activity "Processing data..." -Status "Processing gateway $gatewayName" -PercentComplete (($gatewayIds.IndexOf($gatewayId) / $gatewayIds.Count) * 100)
$dataSources = Get-GatewayDataSources -gatewayId $gatewayId
foreach ($dataSource in $dataSources) {
$dataSourcesList += [PSCustomObject]@{
GatewayId = $gatewayId
GatewayName = $gatewayName
DataSourceId = $dataSource.id
DataSourceName = $dataSource.datasourceName
DataSourceType = $dataSource.datasourceType
ConnectionDetails = $dataSource.connectionDetails
}
}
}
# Export the data sources to a CSV file, You need to define path where GatewayDataSources.csv will be saved
$dataSourcesList | Select-Object GatewayName, GatewayId, DataSourceName, DataSourceId, DataSourceType, ConnectionDetails | Export-Csv "C:\Users\GatewayDataSources.csv" -NoTypeInformation
Write-Output "Data sources have been exported to GatewayDataSources.csv"
#============================================================================
# Part 2: Lists users of all Data sources on On-Premises Gateways for all Gateway IDs mentioned in $gatewayIds = @("","") function.
# Define the output CSV file path, You need to define path where DatasourceUsers.csv will be saved
$outputCsv = "C:\Users\DatasourceUsers.csv"
# Initialize an array to hold the user data
$userData = @()
# Loop through each row in the CSV file
foreach ($dataSource in $dataSourcesList) {
$gatewayId = $dataSource.GatewayId
$gatewayName = $dataSource.GatewayName
$datasourceId = $dataSource.DataSourceId
$datasourceName = $dataSource.DataSourceName
$dataSourceType = $dataSource.DataSourceType
# Display progress
Write-Progress -Activity "Processing data..." -Status "Processing data source $datasourceName" -PercentComplete ((($dataSourcesList.IndexOf($dataSource) / $dataSourcesList.Count) * 100))
# Define the API endpoint
$apiUrl = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId/datasources/$datasourceId/users"
# Make the API request
$response = Invoke-PowerBIRestMethod -Url $apiUrl -Method Get | ConvertFrom-Json
# Extract the user list and add gatewayId and datasourceId to each user
foreach ($user in $response.value) {
$user | Add-Member -MemberType NoteProperty -Name "GatewayId" -Value $gatewayId
$user | Add-Member -MemberType NoteProperty -Name "GatewayName" -Value $gatewayName
$user | Add-Member -MemberType NoteProperty -Name "DataSourceId" -Value $datasourceId
$user | Add-Member -MemberType NoteProperty -Name "DataSourceName" -Value $datasourceName
$user | Add-Member -MemberType NoteProperty -Name "DataSourceType" -Value $dataSourceType
$userData += $user
Write-Output $user.displayName
}
}
# Export the user data to a CSV file
$userData | Select-Object GatewayName, GatewayId, DataSourceId, DataSourceName, DataSourceType, displayName, emailAddress, datasourceAccessRight | Export-Csv -Path $outputCsv -NoTypeInformation
Write-Output "User list exported to $outputCsv"
Here is updated version you can try:
<#
====================================================================================
Power BI Gateway & Data Source Audit Script
====================================================================================
This PowerShell script performs the following tasks:
1. **Setup**:
- Installs and imports the `MicrosoftPowerBIMgmt` module.
- Logs into the Power BI service.
2. **Part 1: Gateway and Data Source Information**:
- Retrieves all Power BI gateway IDs.
- For each gateway:
- Fetches the gateway name.
- Retrieves all associated data sources.
- For each data source:
- Fetches detailed information including credential type and connection details.
- Exports the collected data to `GatewayDataSources.csv`.
3. **Part 2: Data Source User Access**:
- For each data source:
- Retrieves the list of users with access.
- Adds metadata (gateway name, data source name/type).
- Exports the user access data to `DataSourceUsers.csv`.
4. **Part 3: Gateway Overview Report**:
- Groups data by gateway and generates a summary report.
- For each gateway:
- Calculates the total number of data sources.
- Calculates the total number of users.
- Identifies unique users and lists their names and email addresses.
- Identifies unique data source types and lists them.
- Exports the summary data to `PowerBIGatewayOverview.csv`.
5. **Summary Output**:
- Displays the total number of data sources, total users, and unique users.
Output Files:
- `GatewayDataSources.csv`: Contains gateway and data source details.
- `DataSourceUsers.csv`: Contains user access information for each data source.
- `PowerBIGatewayOverview.csv`: Contains a summary of gateway-level metrics, including:
- Total Data Sources
- Total Users
- Unique Users
- List of Unique Users
- List of Unique User Email Addresses
- List of Unique Data Source Types
Author: Amit N Jadhav
====================================================================================
#>
# Install the necessary module if not already installed
if (-not (Get-Module -ListAvailable -Name MicrosoftPowerBIMgmt)) {
Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser
}
# Import the module
Import-Module -Name MicrosoftPowerBIMgmt
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Log in to Power BI
Login-PowerBI > $null
# Define output file path
$outputCsv1 = "<#Enter output path#>\GatewayDataSources.csv"
#====================================================================================
# Part 1 Dynamically fetch all gateway IDs & get Gateway Data sources information
#====================================================================================
$allGateways = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/gateways" -Method Get | ConvertFrom-Json
$gatewayIds = $allGateways.value | Select-Object -ExpandProperty id
# Function to get data sources for a specific gateway
function Get-GatewayDataSources {
param (
[string]$gatewayId
)
$url = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId/datasources"
$response = Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json
return $response.value
}
# Function to get gateway name
function Get-GatewayName {
param (
[string]$gatewayId
)
$url = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId"
$response = Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json
return $response.name
}
# Function to get data source details (to retrieve CredentialType)
function Get-DataSourceDetails {
param (
[string]$gatewayId,
[string]$dataSourceId
)
$url = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId/datasources/$dataSourceId"
$response = Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json
return $response
}
# Initialize an array to store all data sources
$dataSourcesList = @()
# Loop through each gateway ID and get the data sources
foreach ($gatewayId in $gatewayIds) {
$gatewayName = Get-GatewayName -gatewayId $gatewayId
Write-Progress -Activity "Extracting Data Sources" -Status "Processing gateway: $gatewayName" -PercentComplete (($gatewayIds.IndexOf($gatewayId) / $gatewayIds.Count) * 100)
$dataSources = Get-GatewayDataSources -gatewayId $gatewayId
foreach ($dataSource in $dataSources) {
if (-not [string]::IsNullOrEmpty($dataSource.id)) {
$dsDetails = Get-DataSourceDetails -gatewayId $gatewayId -dataSourceId $dataSource.id
$dataSourcesList += [PSCustomObject]@{
GatewayId = $gatewayId
GatewayName = $gatewayName
DataSourceId = $dataSource.id
DataSourceName = $dataSource.datasourceName
DataSourceType = $dataSource.datasourceType
CredentialType = $dsDetails.credentialType
ConnectionDetails = $dataSource.connectionDetails
}
}
}
}
# Export the data sources to a CSV file
$dataSourcesList | Select-Object GatewayName, GatewayId, DataSourceName, DataSourceId, DataSourceType, CredentialType, ConnectionDetails | Export-Csv -Path $outputCsv1 -NoTypeInformation
Write-Host "Gateway Data source information has been collected." -ForegroundColor DarkYellow
#====================================================================================
# Part 2: Lists users of all Data sources
#====================================================================================
$outputCsv = "<#Enter output path#>\DataSourceUsers.csv"
$userData = @()
foreach ($dataSource in $dataSourcesList) {
$gatewayId = $dataSource.GatewayId
$gatewayName = $dataSource.GatewayName
$datasourceId = $dataSource.DataSourceId
$datasourceName = $dataSource.DataSourceName
$dataSourceType = $dataSource.DataSourceType
Write-Progress -Activity "Extracting Data Source Users" -Status "Processing data source: $datasourceName" -PercentComplete ((($dataSourcesList.IndexOf($dataSource) / $dataSourcesList.Count) * 100))
$apiUrl = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId/datasources/$datasourceId/users"
$response = Invoke-PowerBIRestMethod -Url $apiUrl -Method Get | ConvertFrom-Json
foreach ($user in $response.value) {
$user | Add-Member -MemberType NoteProperty -Name "GatewayId" -Value $gatewayId
$user | Add-Member -MemberType NoteProperty -Name "GatewayName" -Value $gatewayName
$user | Add-Member -MemberType NoteProperty -Name "DataSourceId" -Value $datasourceId
$user | Add-Member -MemberType NoteProperty -Name "DataSourceName" -Value $datasourceName
$user | Add-Member -MemberType NoteProperty -Name "DataSourceType" -Value $dataSourceType
$userData += $user
}
}
$userData | Select-Object GatewayName, GatewayId, DataSourceId, DataSourceName, DataSourceType, displayName, emailAddress, datasourceAccessRight | Export-Csv -Path $outputCsv -NoTypeInformation
Write-Host "Gateway Data source Users information has been collected." -ForegroundColor DarkYellow
$uniqueUsers = $userData | Select-Object -Property displayName -Unique
$uniqueUserCount = $uniqueUsers.Count
Write-Host "`nTotal Data Sources: $($dataSourcesList.Count)" -ForegroundColor White
Write-Host "Total Users: $($userData.Count)" -ForegroundColor White
Write-Host "Unique Users: $uniqueUserCount" -ForegroundColor White
Write-Host "Gateway Data sources have been exported to $outputCsv1" -ForegroundColor Green
Write-Host "Gateway Data source users list exported to $outputCsv" -ForegroundColor Green
#====================================================================================
# Part 3: Generate Gateway Overview Report
#====================================================================================
# Define the output file path for the overview report
$outputCsvOverview = "<#Enter output path#>\PowerBIGatewayOverview.csv"
# Prepare data for the overview report
$overviewData = @()
# Group data sources and users by Gateway
$gateways = $dataSourcesList | Group-Object -Property GatewayId
foreach ($gatewayGroup in $gateways) {
$gatewayId = $gatewayGroup.Name
$gatewayName = ($gatewayGroup.Group | Select-Object -First 1).GatewayName
# Data sources for the current gateway
$gatewayDataSources = $gatewayGroup.Group
$totalDataSources = $gatewayDataSources.Count
# Users for the current gateway
$gatewayUsers = $userData | Where-Object { $_.GatewayId -eq $gatewayId }
$totalUsers = $gatewayUsers.Count
# Unique users for the current gateway
$uniqueUsers = $gatewayUsers | Select-Object -Property displayName, emailAddress -Unique
$uniqueUserCount = $uniqueUsers.Count
$uniqueUserNames = $uniqueUsers | ForEach-Object { $_.displayName }
$uniqueUserEmails = $uniqueUsers | ForEach-Object { $_.emailAddress }
# Unique data source types for the current gateway
$uniqueDataSourceTypes = $gatewayDataSources | Select-Object -Property DataSourceType -Unique
$uniqueDataSourceTypeNames = $uniqueDataSourceTypes | ForEach-Object { $_.DataSourceType }
# Add the gateway overview data to the report
$overviewData += [PSCustomObject]@{
GatewayName = $gatewayName
GatewayId = $gatewayId
TotalDataSources = $totalDataSources
TotalUsers = $totalUsers
UniqueUsers = $uniqueUserCount
UniqueDataSourceTypeList = ($uniqueDataSourceTypeNames -join "; ") # Join unique data source types into a single string
UniqueUserList = ($uniqueUserNames -join "; ") # Join unique user names into a single string
UniqueUserEmailList = ($uniqueUserEmails -join "; ") # Join unique user email addresses into a single string
}
}
# Export the overview data to a CSV file
$overviewData | Export-Csv -Path $outputCsvOverview -NoTypeInformation
# Display a message indicating the overview report has been generated
Write-Host "Power BI Gateway Overview report has been generated." -ForegroundColor Green
Write-Host "Overview report exported to $outputCsvOverview" -ForegroundColor Green
Instructions for Running above PowerShell Script:
Step 1: Prerequisites
Ensure PowerShell is Installed:
The script requires PowerShell 5.1 or later. To check your PowerShell version, run:
$PSVersionTable.PSVersion
Install Required Module:
The script uses the MicrosoftPowerBIMgmt module. If it is not already installed, the script will attempt to install it automatically. However, you can manually install it beforehand by running:
Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser
Enable TLS 1.2:
The script includes a command to enable TLS 1.2 for secure HTTPS connections. Ensure your system supports TLS 1.2.
Power BI Admin Access:
You must have administrative access to the Power BI service to retrieve gateway and data source information.
File Paths:
Update the file paths in the script (e.g., <#Enter output path#>) to specify where the output CSV files should be saved.
Step 2: Prepare the Script
Copy the Script:
Copy the entire PowerShell script into a .ps1 file. For example, save it as PowerBIGatewayAudit.ps1.
Update File Paths:
Replace <#Enter output path#> placeholders in the script with valid file paths on your system. For example:
$outputCsv1 = "C:\Reports\GatewayDataSources.csv"
$outputCsv = "C:\Reports\DataSourceUsers.csv"
$outputCsvOverview = "C:\Reports\PowerBIGatewayOverview.csv"
Verify Permissions:
Ensure you have write permissions to the directories where the output files will be saved.
Step 3: Run the Script
Open PowerShell:
Open PowerShell as an administrator to ensure you have the necessary permissions.
Navigate to the Script Directory:
Use the cd command to navigate to the directory where the script is saved. For example:
cd C:\Scripts
Execute the Script:
Run the script by typing:
.\PowerBIGatewayAudit.ps1
Log in to Power BI:
When prompted, log in to the Power BI service using your admin credentials.
Step 4: Review the Output
Check the Console Output:
The script will display progress updates and a summary of the results, including:
Total Data Sources
Total Users
Unique Users
Locate the Output Files:
The script generates the following CSV files:
GatewayDataSources.csv: Contains gateway and data source details.
DataSourceUsers.csv: Contains user access information for each data source.
PowerBIGatewayOverview.csv: Contains a summary of gateway-level metrics.
Open the Files:
Open the CSV files in Excel or any text editor to review the data.
Step 5: Troubleshooting
Module Installation Issues:
If the MicrosoftPowerBIMgmt module fails to install, ensure you have an active internet connection and run PowerShell as an administrator.
Login Issues:
Ensure your Power BI account has the necessary permissions to access gateway and data source information.
File Path Errors:
Verify that the directories specified in the file paths exist and are writable.
Connection Errors:
If you encounter HTTPS connection errors, ensure TLS 1.2 is enabled by running:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Hello,
for the record, point 1 (list of data sources) can be done using the API :
https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/getdatasources
Hi @Anonymous,
After research, there is no such list including data source and users. You need to produce them one by one.
Best Regards,
Angelia
Angelia, Thanks for the quick response
Is there any chance of this beeing made available in future. Is there any Idea that i can vote(link).
Hi @Anonymous,
Please review the following idea and comment on it.
https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/31710763-gateway-management-tool-cli
Thanks,
Angelia
Thans Angelia for the link. I voted and also had a coment i the link you provided.
Hope this comes back sooner.
Hi @Anonymous,
It's my pleasure to help you, could you please mark the useful reply as answer, so more people like you can get information easily.
Thanks,
Angelia
User | Count |
---|---|
47 | |
31 | |
27 | |
27 | |
26 |
User | Count |
---|---|
56 | |
55 | |
36 | |
33 | |
28 |