We have a PowerShell script that uses the "Invoke-PowerBIRestMethod" to force a dataset to refresh. The script has been working without issues for the past several months. For the last week and a half, we have started receiving the error stating the connection was closed by the host. At first it was very random but then in the last couple of days, the error is occurring consistently.
We pass in the workspace GUID, dataset GUID, and the file path that stores the password for the user.
I have included a portion of our script (it uses parameters to pass in the workspace GUID, dataset GUID, and the file path that stores the password for the user) and the full error message below.
Does anyone have any insights as to what the issue could be?
Thanks,
----------------------------------------------------------------------------------------------------------
Script:
param( [string] $WSIDAdmin, [string] $DSIDRefresh, [string] $PBIKEY )
Set-ExecutionPolicy Unrestricted
$passwordFile = $PBIKEY
$username = "EXXXX@xpo.com"
$EBASecurityURL = 'groups/' + $WSIDAdmin + '/datasets/' + $DSIDRefresh + '/refreshes'
$password = Get-Content $passwordFile | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $password)
Connect-PowerBIServiceAccount -Credential $credential
$MailFailureNotify = @{"notifyOption"="MailOnFailure"}
Invoke-PowerBIRestMethod -Url $EBASecurityURL -Method Post -Body $MailFailureNotify }
Full error message:
{System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PowerBI.Commands.Common.PowerBISettings.d__6.MoveNext()} Message : One or more errors occurred. Data : {} InnerException : System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PowerBI.Commands.Common.PowerBISettings.d__6.MoveNext() TargetSite : TResult GetResultCore(Boolean) StackTrace : at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.PowerBI.Commands.Common.PowerBISettings..ctor(String settingsFilePath) at Microsoft.PowerBI.Commands.Common.PowerBICmdlet.GetDefaultInitFactory() at lambda_method(Closure ) at System.Management.Automation.CommandProcessor.Init(CmdletInfo cmdletInformation) HelpLink : Source : mscorlib HResult : -2146233088
Invoke-PowerBIRestMethod -Url groups/03752544-651f-4269-b117-92bba89fd007/datasets/99b9b70b-509c-4a66-a8f4-0e4eb4d175da/refreshes-Method Post -Body
Connect-PowerBIServiceAccount -Credential System.Management.Automation.PSCredential