Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
Hi,
I have to do Synchronous Data Refresh , please help on this
Connect-PowerBIServiceAccount
$token = Get-PowerBIAccessToken -AsString
$Workspace = Get-PowerBIWorkspace -Name 'CitiDriver UAT'
$WorkspaceId = $Workspace.Id
write-host $WorkspaceId
$report = Get-PowerBIReport -WorkspaceId $WorkspaceId -Name ReportName
$reportId = $report
write-host $reportId
$dataset = Get-PowerBIDataset -WorkspaceId $WorkspaceId
$datasetId = $dataset
$token = Get-PowerBIAccessToken -AsString
write-host $token
# Building Rest API header with authorization token
$authHeader = @{
"Authorization"= $token
"Content-Type" = "application/json"
}
$postParams = @{
"datasetId" = "$datasetId"
}
$jsonPostBody = $postParams | ConvertTo-JSON
$u = "https://api.powerbi.com/v1.0/myorg/datasets/8524fac6-699d-4b37-874c-dabb6fd9abf8/refreshes"
$t = Invoke-RestMethod -Uri $u -Method Post -Headers $authHeader -ContentType "application/json" |Out-Null
Start-Sleep -Seconds 600
$result = @()
$uril = "https://api.powerbi.com/v1.0/myorg/datasets/8524fac6-699d-4b37-874c-dabb6fd9abf8/refreshes"
$restResponse1 = Invoke-RestMethod -Uri $uril -Method GET -Headers $authHeader -ContentType "application/json"
$x=$restResponse1.value | Select-Object -First 1
$startime = $x.startTime
$endtime = $x.endTime
$status = $x.status
$props = [ordered]@{
"starttime" = $startime
"endttime" = $endtime
"status" = $status
}
$result += @(New-Object pscustomobject -Property $props)
$outputpath = "C:\output.csv"
$result |Export-Csv -Path $outputpath -NoTypeInformation
$To = "[email protected]"
$emailconnection = "https://management.azure.com:443/subscriptions/8e1a5828-5178-45ba-a9bf-72616f9c6e06/resourceGroups/C..."
$emailoutput = [PSCustomobject]@{
"TO" = $To
"Subject" = "Powerbi"
"Body" = $result
}
$jsonPostBody = $emailoutput | ConvertTo-Json -Depth 5
Invoke-RestMethod -Uri $emailconnection -Body $jsonPostBody -ContentType 'application/json' -Method Post | Out-Null
Hi @halsa_88 ,
Have trouble to follow.
Please share more details about the Script logic.
Best Regards,
Jay
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.
| User | Count |
|---|---|
| 27 | |
| 26 | |
| 25 | |
| 20 | |
| 16 |
| User | Count |
|---|---|
| 48 | |
| 45 | |
| 43 | |
| 39 | |
| 37 |