Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi everyone,
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.
Here is a part of my script that calls REST API to export the reprot in pdf format.
Login-PowerBI
$groupid = "Hidden"
$Reportid = "Hidden"
$Folder = "c:\temp\"
$Body = "{`”format`”:`”pdf`”}"
$filename = $Folder + "PowerBIMetrics.pdf"
$StatusCheck=0
# Get token
$token = Get-PowerBIAccessToken -AsString
##write-host $token
# Building Rest API header with authorization token
$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 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.
I also tried to used otther method from link below but no luck either.
PowerShell - The underlying connection was closed: An unexpected error occurred on a send. - darrenj...
Thank you.
Eric
Solved! Go to Solution.
Hi,
This could be as I am using a proxy server / connected to the client network using VPN.
TBH, the only way to find out is to go to office and try to execute this API and see it works.
I will keep an update on this.
Thanks.
@nitishsh91 To add in more...
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.
Reports - Export To File - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Are you trying it in a browser within client network?
If yes then please can try opening powerbi on your mobile or personal laptop browser incognito mode and try it to see if it gives any result or not.
Yes it was changed recently and this was my guess that it's causing an issue for you.
This notification has been going in for a while and changes are being rolled out to disabled old tls versions.
Hi,
This could be as I am using a proxy server / connected to the client network using VPN.
TBH, the only way to find out is to go to office and try to execute this API and see it works.
I will keep an update on this.
Thanks.
@nitishsh91
Thanks for your reply , I added that TLS line on the top of the code and ran with same error.
You mentioned the issue might be with TLS in my firewall which is not allowing the connection ? Do you know how we could confirm/check on this?
I hope we can get bottom of this.
FYI - This was changed recently , could this be the reason for this issue ?
Enable TLS 1.2 support as Azure AD TLS 1.0/1.1 is deprecated - Active Directory | Microsoft Learn
Regards,
Eric
Hi @EricShahi
I also suspect issue with tls in your firewall from where you are trying to run this command, please add that line to top of your script and see if it helps.
Also use try it feature from below link and see if that works and if it does work then issue is with your firewall which is not allowing the connection.
https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-report
Please let me know if it helps.
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.