Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
halsa_88
New Member

Powershell Script for Synchronous Data Refresh

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 = "atultiwari.eng06@gmail.com"
$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

1 REPLY 1
Anonymous
Not applicable

Hi @halsa_88 ,

 

Have trouble to follow.

Please share more details about the Script logic.

 

Best Regards,

Jay

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.