Forum Discussion
Forbidden (403) error when using While statement in PowerShell URL
- 1 year ago
Can you try below powershell script once. this is working fine for me
"<< API >>" > while ($true) { >> $payload = @( >> @{ >> "Date" = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") # Current UTC DateTime >> "Name" = "AAAAA555555" >> "Marks" = Get-Random -Minimum 0 -Maximum 100 # Generate a random number >> } >> ) >> >> $headers = @{ >> "Content-Type" = "application/json" >> } >> >> # Send data to Power BI >> Invoke-RestMethod -Method Post -Uri "$endpoint" -Headers $headers -Body (ConvertTo-Json $payload -Depth 3) >> >> Write-Host "Data sent at $(Get-Date)" >> >> Start-Sleep -Seconds 10 # Wait for 10 seconds before the next update >> }PFB screenshot for same:
'
Thanks,
Prashanth Are
MS Fabric community support
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query
Can you try below powershell script once. this is working fine for me
"<< API >>"
> while ($true) {
>> $payload = @(
>> @{
>> "Date" = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") # Current UTC DateTime
>> "Name" = "AAAAA555555"
>> "Marks" = Get-Random -Minimum 0 -Maximum 100 # Generate a random number
>> }
>> )
>>
>> $headers = @{
>> "Content-Type" = "application/json"
>> }
>>
>> # Send data to Power BI
>> Invoke-RestMethod -Method Post -Uri "$endpoint" -Headers $headers -Body (ConvertTo-Json $payload -Depth 3)
>>
>> Write-Host "Data sent at $(Get-Date)"
>>
>> Start-Sleep -Seconds 10 # Wait for 10 seconds before the next update
>> }
PFB screenshot for same:
'
Thanks,
Prashanth Are
MS Fabric community support
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query
- HassanRizvi1 year agoNew Member
Hi Prashanth,
It is really helpful for me, can you please guide me how can I make the Power Bi report to update on its own.
with your code, I have to click on the refresh button to update the graph.
Thanks for this immense support