I have a powershell script that pulls reports from SSRS and packages/aggregates these as worksheets within an Excel workbook.
Recently, the script has begin to throw the following:
"TerminatingError(New-Object): "Exception calling ".ctor" with "0" argument(s): "Error creating window handle.""
when attempting to execute:
$rv = New-Object Microsoft.Reporting.WinForms.ReportViewer
within a function.
Again, this is a recent occurrence. I can't determine what has changed.
The script executes a few hundred calls to create a ReportViewer. These succeed.
When I run the script from the PowerShell ISE, I see the exception above thrown once. It occurs in the same spot (in relation to the few hundred calls to create a ReportViewer and obtain a SSRS report) each time the script is run. However, the remaining calls (after the one failure) to create new ReportViewer objects succeed. Only one report will fail to be pulled. ($ErrorActionPreference is set to "Continue").
When I execute the script (under the same administrator user credentials) by way of task scheduler with "Run with highest privileges" enabled, the behavior differs. The exception occurs at the same spot (in relation to the few hundred calls to create a ReportViewer and obtain a SSRS report), but thereafter every following call to create a ReportViewer object and pull a report fails. Instead of one report failing to be pulled, all successive attempts at pulling reports fail after the initial failure.
I've tried such things as increasing memory to the script. I'm diligently removing variables and garbage collecting. I'm unsure as to 1) why the call to the new-object cmdlet fails at a consistent spot after succeeding many times prior and 2) unsure as to why the behavior is different (under the same credentials) when running within the ISE environment versus running the script as a scheduled task.
I'd appreciate any insight or suggestions you might have.
Thank you
PS>TerminatingError(New-Object): "Exception calling ".ctor" with "0" argument(s): "Error creating window handle."" New-Object : Exception calling ".ctor" with "0" argument(s): "Error creating window handle." At C:\ReportDistribution\SSRSDistributeProd.ps1:36 char:9 + $rv = New-Object Microsoft.Reporting.WinForms.ReportViewer; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Aucun commentaire:
Enregistrer un commentaire