Forum Discussion

MarkH's avatar
MarkH
Icon for Helper I rankHelper I
1 year ago
Solved

extracting permissions from the service using powershell

Using the following powershell script I can extract user information and then use powerquery on the result to extract WORKSPACE level permissions. I wish to extract App level permissions and possibly...
  • MarkH's avatar
    MarkH
    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"

    ####################