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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Jayasreeb
Frequent Visitor

PowerShell Script to Refresh PowerBI Dataset is failing

We use PowerShell script to refresh PowerBI Datasets. We run these scripts from SQL agent job.

The powershell script was running fine from our server for many days. But all of a sudden it started failing.I checked with Infrastructure team to see if any firewall settings are blocking the call to PowerBI. We couldn't find anything .

 

The same powershell script when ran from my desktop works fine and refreshes dashboard, but when it runs from server it gives me following error 

 

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.At 
+ ... $response = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

 

 

Any help to troubleshoot this issue is greatly appreciated.

2 ACCEPTED SOLUTIONS
v-xulin-mstf
Community Support
Community Support

Hi @Jayasreeb 

 

It seems that the error is coming from Office 365 change were TLS 1.0 is being superseded by TLS 1.2. Since it's still working for my default configuration, I guess my tenant is not yet forced on TLS 1.2, but others already switched. The fix is simple. Before executing Invoke-RestMethod, just run this:

[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12

If you want to learn more, please refer:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?vi...

https://evotec.xyz/invoke-restmethod-the-underlying-connection-was-closed-an-unexpected-error-occurr...

 

Best Regards,

Link

View solution in original post

Hi @v-xulin-mstf ,

 The solution you provided worked. My powershell script is not throwing error anymore after adding that piece of line. I appreciate your help with fixing this outstanding issue that I am working on from many days.

View solution in original post

5 REPLIES 5
v-xulin-mstf
Community Support
Community Support

Hi @Jayasreeb 

 

It seems that the error is coming from Office 365 change were TLS 1.0 is being superseded by TLS 1.2. Since it's still working for my default configuration, I guess my tenant is not yet forced on TLS 1.2, but others already switched. The fix is simple. Before executing Invoke-RestMethod, just run this:

[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12

If you want to learn more, please refer:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?vi...

https://evotec.xyz/invoke-restmethod-the-underlying-connection-was-closed-an-unexpected-error-occurr...

 

Best Regards,

Link

Hi @v-xulin-mstf ,

 The solution you provided worked. My powershell script is not throwing error anymore after adding that piece of line. I appreciate your help with fixing this outstanding issue that I am working on from many days.

GilbertQ
Super User
Super User

Hi @Jayasreeb 

 

I would chat to your network Admin and make sure it can connect to the internet.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

GilbertQ
Super User
Super User

Hi @Jayasreeb 

 

From the error it would appear to me that the server does not have access to the Power BI REST APIs?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Thanks @GilbertQ  for the reply. How can I give my server access to PowerBI rest API's.

 

my process was working fine for many days. All of a sudden on one day,it started failing.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors