Telegraf exec plugin - powershell script errors not seen/logged

I’m using Telegraf to gather some data using a Powershell script, it gives an error which is not seen by Telegraf and therefore is not logged

script file (myScript.ps1):

Get-CimInstance CIM_LogicalDisk -ComputerName _RemoteHost_

Note: in the full script the data gets formatted in influx line format, but to show the problem that’s not needed)

When I run myScript.ps1 from Powershell or cmd

Powershell.exe -Command "C:\Monitoring\telegraf\myScript.ps1"

I get the following error:

Get-CimInstance : Access is denied.

So far everything is ok.

If I create a Telegraf conf file that executes this command (extract of test.conf):

  ## Log
  debug = true
  quiet = false

  ##  empty string means to log to stderr.
  #logfile = ""

  ## Commands array
  commands = [
    'powershell.exe "C:\Monitoring\telegraf\myScript.ps1"'

and then I test it

.\telegraf.exe --config .\test.conf --test

2019-12-06T14:05:17Z I! Starting Telegraf 1.12.5
2019-12-06T14:05:17Z D! [agent] Initializing plugins

As you can see no error is reported, but I expect to see one since an exception is raised by the script.
Have you ever faced this problem?

This has been solved on github.

The problem is the exit code returned by powershell to the cmd, see the link above for reference