To Introduce myself : Working as a Power BI Developer with PBI Admin access.
My Powershell script stoped working suddenly and prompting me an error saying the underlying connection was closed. This was all working fine few days back.
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a receive. At line:25 char:7 Invoke-RestMethod -Method Post -uri $url1 -Headers $authHeader ... CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExcepti on FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Login-PowerBI
$groupid = "Hidden"
$Reportid = "Hidden"
$Folder = "c:\temp\"
$Body = "{`”format`”:`”pdf`”}"
$filename = $Folder + "PowerBIMetrics.pdf"
$StatusCheck=0
$token = Get-PowerBIAccessToken -AsString
$authHeader = @{
"Authorization"= $token
"Content-Type" = "application/json"
}
$url1 = "https://api.powerbi.com/v1.0/myorg/groups/$groupid/reports/$Reportid/ExportTo"
Invoke-RestMethod -Method Post -uri $url1 -Headers $authHeader -body $Body'
I have also tried to look for solution and many of them (Power BI community/ DBA) is saying I need to add extra line of code below before I execute the Invoke-ResMethod command line,
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Unfortunately, I'm getting same error message if i add above line.
I passed in parameters groupId/reportid/body and click "run" but nothing happens, it doesn't give me any result, this was working fine before. https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file#code-try-0