Forum Discussion

paritoshmishra's avatar
5 years ago
Solved

Get Workspace By Capacity Name

Is any way or rest API to get Workspace list by Capacity Name attached ..   TIA  Paritosh Mishra 
  • lbendlin's avatar
    5 years ago

     

     

    # Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
    function GetAuthToken
    {
        if(-not (Get-Module AzureRm.Profile)) {
            Import-Module AzureRm.Profile
        }
        $clientId = "your client id here"
        $redirectUri = "urn:ietf:wg:oauth:2.0:oob"
        $resourceAppIdURI = "https://analysis.windows.net/powerbi/api"
        $authority = "https://login.microsoftonline.com/common/oauth2/authorize";
        $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
        $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")
        return $authResult
    }
    
    # Get the auth token from AAD
    $token = GetAuthToken
    
    # Building Rest API header with authorization token
    $authHeader = @{
        'Content-Type'='application/json'
        'Authorization'=$token.CreateAuthorizationHeader()
    }
    
    # get workspaces with capacityId where present
    
    $uri = "https://api.powerbi.com/v1.0/myorg/groups"
    $v = (Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET).value 
    $v | Select id,isReadOnly,isOnDedicatedCapacity,capacityId,name | Format-Table -AutoSize