Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
As I am new to powershell coding, so I need your help in below topic :
While writing the below piece of powershell code to get the list of workspaces in my organization I am getting the below error :
PowerShell Code :
#Remember to import Exchange Online module and connect.
#$Username = "MY_USERNAME"
#$Password = ConvertTo-SecureString -String "MY_PASSWORD" -AsPlainText -Force
#$UserCredential =New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $Username, $Password
#Connect-MsolService -credential $UserCredential
#Define $info array
#$info = @()
#To edit the permission of app please access portal.azure.com in AAD
$clientId = "FILL ME IN"
# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
$adal = "${env:ProgramFiles}\WindowsPowerShell\Modules\AzureRM.profile\5.8.4\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "${env:ProgramFiles}\WindowsPowerShell\Modules\AzureRM.profile\5.8.4\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
$redirectUri = "https://oauth.powerbi.com/PBIAPIExplorer"
$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()
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
#Lets get all Groups
$uri = "https://api.powerbi.com/v1.0/myorg/groups"
$groups = Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET -Verbose
$groups.value
Error Message while running the script :
Although, in app settings redirect URI and resource APP ID uri are pointing to the respective links.
Also, I am following the below links as reference:
Power BI REST APIs for embedded analytics and automation - Power BI REST API | Microsoft Docs
Thank you in advance
Solved! Go to Solution.
Hi @Anonymous ,
The resource must be either the client ID of the app or if you want to specify the resource parameter in form of URL, you need to Expose an API on the application and add required scopes. The Resource URL in the request must match with the Application ID URI. Please refer to the highlighted sections in the screenshot below:
Once this is done, you need to add permissions for that API under API permissions section of the application and grant admin consent.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
The resource must be either the client ID of the app or if you want to specify the resource parameter in form of URL, you need to Expose an API on the application and add required scopes. The Resource URL in the request must match with the Application ID URI. Please refer to the highlighted sections in the screenshot below:
Once this is done, you need to add permissions for that API under API permissions section of the application and grant admin consent.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
6 | |
6 | |
3 | |
2 | |
2 |
User | Count |
---|---|
6 | |
5 | |
4 | |
4 | |
3 |