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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-jayw-msft
Community Support
Community Support

Hi @halsa_88 ,

 

Have trouble to follow.

Please share more details about the Script logic.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.