Options

Handle NAV errors in powershell

ArturoArturo Member Posts: 30
edited 2014-09-26 in NAV Three Tier
Hello,
I'm using powershell to execute some CU, something like this:
Invoke-NAVCodeunit -CodeunitId 7172409 -ServerInstance DynamicsNAV71 -CompanyName $Comp.CompanyName

And the console returns (in red!) something like this:
Invoke-NAVCodeunit : " The vendor XXX is blocked"
I need to handle the posible errors wich the CU returns to send mail reporting, but there is no way to "catch" that exception as an error.

Any idea??
Thank you very much!!

Comments

  • Options
    ArturoArturo Member Posts: 30
    I got it:
    $Error.Clear()
    Invoke-NAVCodeunit.... # you're NAV process
    if ($Error.Exception.message -notlike "")
    {
    SendNavMail $MyInvocation.MyCommand.Name $Comp.CompanyName $Error.Exception.message
    }

    I crated the function SendnavMail in a new module. Its important to clear de error variable because its acumulative.
Sign In or Register to comment.