Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Trapping Excel error messages in Powershell Scheduled scripts

$
0
0

OK, part of the confusion is that you’re looking at an error that has been wrapped in at least one extra layer of exception (MethodInvocationException, which is a PowerShell thing.) You can get at the original error like this; see if it gives you better information:

try
{
    $objExcel = New-Object -ComObject "Excel.Application" 
    $objExcel.Visible = $False
    $objExcel.DisplayAlerts = $False
    $UserWorkBook = $objExcel.Workbooks.Open($strInputFile)
}
catch
{
    $exception = $_.Exception

    while ($null -ne $exception.InnerException)
    {
        $exception = $exception.InnerException
    }

    # Display the properties of the original exception
    $exception | Format-List * -Force
}

Viewing all articles
Browse latest Browse all 13067

Latest Images

Trending Articles



Latest Images