Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
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
Hi
I have Power BI Report with a OData Dataset getting data from Dynamics365. I created in Power Bi Desktop.
Then I have a PowerBI.com workspace. Using the PowerBI.com Odata API, Azure AD API and PowerShell I am able to:
The refresh takes place at the requested times (or it tries to) because the refresh fails with the following error:
"The credentials provided for the OData source are invalid."
Since I was able to refresh earlier just after updating with the access token, I am guessing that the access token is no longer valid and PowerBi was not able to refresh it by itself.
My question is:
Any help/suggestions are much appriciated.
Thanks
Mads
---
My code for generating the access token:
Function Get-AADToken {
$Username = "<secret-username-to-d365user-goes-here>"
$Password = ConvertTo-SecureString "<secret-password-to-d365user-goes-here>" -AsPlainText -Force
$ClientId = "<client-appid-to-d365-app-registration-goes-here>"
$Resource = "<url-to-d365-instance-goes-here>"
$authorityUrl = "https://login.microsoftonline.com/common/oauth2/authorize"
## load active directory client dll
$typePath = $PSScriptRoot + "\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
Add-Type -Path $typePath
Write-Verbose "Loaded the Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
Write-Verbose "Using authority: $authorityUrl"
$authContext = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext -ArgumentList ($authorityUrl)
$credential = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential -ArgumentList ($UserName, $Password)
Write-Verbose "Trying to aquire token for resource: $Resource"
$authResult = $authContext.AcquireToken($Resource, $clientId, $credential)
Write-Verbose "Authentication Result retrieved for: $($authResult.UserInfo.DisplayableId)"
return $authResult.AccessToken
}
$accesstoken = Get-AADToken
Topic bump. Still looking for answers
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 |