Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
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 April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 8 | |
| 8 | |
| 4 | |
| 3 | |
| 2 |