Forum Discussion
extracting permissions from the service using powershell
- 1 year ago
Thnaks for your help everyone. This is what i ended up with for finding App permissions. 🙂
####################
# Connect to Power BI Service
Connect-PowerBIServiceAccount# Define the API endpoint to get all apps
$appsApiUrl = "https://api.powerbi.com/v1.0/myorg/admin/apps?%24top=150"# Get the list of all apps
$appsResponse = Invoke-PowerBIRestMethod -Url $appsApiUrl -Method Get# Parse the JSON response
$responseJson = $appsResponse | ConvertFrom-Json# Extract the app data from the parsed JSON
$apps = $responseJson.value# Extract id, name, and workspaceId
$filteredapps = $apps | Select-Object -Property id, name, workspaceId# Initialize an array to hold the final output
$finalOutput = @()# Loop through each app and get the users
foreach ($app in $filteredapps) {
$appId = $app.id
$appName = $app.name
$apiUrl = "https://api.powerbi.com/v1.0/myorg/admin/apps/$appId/users"
# Get the list of users for the current app
$response = Invoke-PowerBIRestMethod -Url $apiUrl -Method Get
# Parse the JSON response
$appusers = $response | ConvertFrom-Json# Create a custom object for the app and its users
$appData = [PSCustomObject]@{
AppId = $appId
AppName = $appName
Users = $appusers.value
}
# Add the custom object to the final output array
$finalOutput += $appData
}# Convert the final output array to JSON
$finalOutputJson = $finalOutput | ConvertTo-Json -Depth 3# Output the final JSON to a file
$finalOutputJson | Out-File -FilePath "C:\temp\apps_user_access.json"####################
Hi. Apps api doesn't work like workspaces. You can get them and the users. But it's different. First you should get all the apps you want to check users and then loop them one by one running:
https://learn.microsoft.com/en-us/rest/api/power-bi/admin/apps-get-app-users-as-admin
That way you can get users from an app.
I hope that helps,
Thnaks for your help everyone. This is what i ended up with for finding App permissions. 🙂
####################
# Connect to Power BI Service
Connect-PowerBIServiceAccount
# Define the API endpoint to get all apps
$appsApiUrl = "https://api.powerbi.com/v1.0/myorg/admin/apps?%24top=150"
# Get the list of all apps
$appsResponse = Invoke-PowerBIRestMethod -Url $appsApiUrl -Method Get
# Parse the JSON response
$responseJson = $appsResponse | ConvertFrom-Json
# Extract the app data from the parsed JSON
$apps = $responseJson.value
# Extract id, name, and workspaceId
$filteredapps = $apps | Select-Object -Property id, name, workspaceId
# Initialize an array to hold the final output
$finalOutput = @()
# Loop through each app and get the users
foreach ($app in $filteredapps) {
$appId = $app.id
$appName = $app.name
$apiUrl = "https://api.powerbi.com/v1.0/myorg/admin/apps/$appId/users"
# Get the list of users for the current app
$response = Invoke-PowerBIRestMethod -Url $apiUrl -Method Get
# Parse the JSON response
$appusers = $response | ConvertFrom-Json
# Create a custom object for the app and its users
$appData = [PSCustomObject]@{
AppId = $appId
AppName = $appName
Users = $appusers.value
}
# Add the custom object to the final output array
$finalOutput += $appData
}
# Convert the final output array to JSON
$finalOutputJson = $finalOutput | ConvertTo-Json -Depth 3
# Output the final JSON to a file
$finalOutputJson | Out-File -FilePath "C:\temp\apps_user_access.json"
####################