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.
Hi!
I am currently using PowerShell to make an API call to refresh a dataset. Here is the code:
# Credentials
$AppId = "<AppId>"
$TenantId = "<TenantId>"
$ClientSecret = "<ClientSecret>"
# Creating secure string & credential for Application ID and client secret
$PbiSecurePassword = ConvertTo-SecureString $ClientSecret -Force -AsPlainText
$PbiCredential = New-Object Management.Automation.PSCredential($AppId, $PbiSecurePassword)
# Connect to the Power BI Service Account
Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $TenantId -Credential $PbiCredential
# Set the value of the Group ID and Dataset Name
$GroupId = '<GroupId>'
$DatasetName = '<DatasetName>'
# Get the Dataset ID of the Target Dataset
$Datasets = Get-PowerBIDataset -WorkspaceId $GroupId
$DatasetId = ($Datasets | Where-Object { $_.Name -eq $DatasetName }).Id.Guid
Write-Host $DatasetId
# Refresh the Dataset
try {
$Headers = Get-PowerBIAccessToken
Invoke-RestMethod -Headers $Headers -Uri "https://api.powerbi.com/v1.0/myorg/groups/${GroupId}/datasets/${DatasetId}/refreshes" -Method 'Post' -Body ([pscustomobject]@{type='full'; commitMode='transactional'; applyRefreshPolicy='true'; notifyOption='MailOnCompletion'} | ConvertTo-Json -Depth 2 -Compress)
Write-Output "Successfully triggered a PowerBI Dataset Refresh."
} catch {
if ($_.Exception.Response.StatusCode.value__ -eq 400) {
Write-Output "A refresh is currently running."
$RefreshStatus = Invoke-RestMethod -Headers $Headers -Uri "https://api.powerbi.com/v1.0/myorg/groups/${GroupId}/datasets/${DatasetId}/refreshes" -Method 'Get'
$LatestRefresh = $RefreshStatus.value[0]
$Status = $LatestRefresh.status
$StartTime = $LatestRefresh.startTime
$EndTime = $LatestRefresh.endTime
$Output = @"
Status: $Status
Start Time: $StartTime
End Time: $EndTime
"@
Write-Output $Output
} else {
Write-Output "An error occurred: $($_.Exception.Message)"
}
}
The script works as intended when running locally. If the dataset is not being refreshed currently then a refresh is triggered. If the dataset is currently being refreshed then the status is displayed. However, I am trying to deploy this to an automation software called ActiveBatch which allows you to schedule and trigger PowerShell jobs.
When I run the job on ActiveBatch, the job fails with a 404 Error. Specifically the following:
The remote server returned an error: (404) Not Found.
The service account has access to the dataset and there is no permissions issue. I saw a similar post regarding this which said that this is an issue related to AD group permissions. However, that is not the case here since the service account is added as an Admin to the dataset and the script works as intended locally.
What is strange is that the script works fine when I am running it on my laptop but it fails when running on ActiveBatch using the same service account credentials.
Thank you in advance!
Hi @Anonymous ,
Based on the information you've provided, it seems like your PowerShell script works as expected when executed locally but encounters a 404 Not Found error when scheduled and run through ActiveBatch. This discrepancy suggests that the issue might not be with the script itself but rather with how ActiveBatch interacts with the Power BI API or the environment it's running in.
A few areas to investigate:
1. Endpoint Accessibility: Ensure that the ActiveBatch environment has network access to api.powerbi.com. It's possible that network policies or firewalls in the ActiveBatch environment are blocking access to the Power BI API endpoints.
2. PowerShell Environment: Verify that the PowerShell version and modules available in the ActiveBatch environment are the same as those on your local machine. Differences in PowerShell versions or missing modules could lead to unexpected behavior.
3. Service Principal Permissions: Double-check that the service principal used has the necessary API permissions assigned in Azure AD and that it's not restricted in any way when running from the ActiveBatch environment.
Best regards,
Community Support Team_Binbin Yu
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 |
---|---|
69 | |
68 | |
40 | |
29 | |
26 |
User | Count |
---|---|
89 | |
49 | |
44 | |
38 | |
37 |