# Telegraf inputs.exec formatting - Windows powershell

**URL:** <https://community.influxdata.com/t/telegraf-inputs-exec-formatting-windows-powershell/16527>\
**Category:** Systems\
**Tags:** windows, getting-started\
**Created:** [October 30, 2020, 8:15am UTC](https://community.influxdata.com/t/telegraf-inputs-exec-formatting-windows-powershell/16527 "2020-10-30T08:15:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptica](https://avatars.discourse-cdn.com/v4/letter/p/5f9b8f/32.png) [@ptica](https://community.influxdata.com/u/ptica)\
**Post date:** [October 30, 2020, 8:15am UTC](https://community.influxdata.com/t/telegraf-inputs-exec-formatting-windows-powershell/16527/1 "2020-10-30T08:15:16Z")

</div>

I run a script that monitors time offsets based on a log and produces output doing a Write-Output in format “offset,source=$gps\_source protocol=$protocol offset=$offset” which when run produces output like below  
offset,192.168.0.100 NTP -0.00111111111  
this is formatted in config with  
[[inputs.exec]]  
[command] = ‘powershell “c://progra~1//telegraf/test.ps1”’  
timeout=“10s”  
interval=“10s”  
name\_suffix=time.stats  
data\_format=“influx”

when running a test with telegraf -config telegraf.config --test I get  
[inputs.exec]: error in plugin: metric parse error: expected field at offset xx:“offset,source=192.168.0.100 protocol=NTP offset=-0.001111111\n”

I’m likely doing something wrong with formatting but don’t quite know what exactly. I tried removing the whitespace between source and protocol replacing with coma so it’s measurement,tag=value,tag=value field\_key=value and that looks somewhat better but a bit of a mess  
offsettime.stats,host=server5,protocol=ntp,source=192.168.0.100 offset=-0.0011111111 16040448399870809  
How to format this correctly?

---

<div class="post-metadata">

**Author:** ![Giovanni\_Luisotto](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/giovanni_luisotto/32/4017_2.png) [@Giovanni\_Luisotto](https://community.influxdata.com/u/Giovanni_Luisotto)\
**Post date:** [October 30, 2020, 9:48am UTC](https://community.influxdata.com/t/telegraf-inputs-exec-formatting-windows-powershell/16527/2 "2020-10-30T09:48:01Z")

</div>

Your sting looks like a valid [line protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/)

```auto
offsettime.stats,host=server5,protocol=ntp,source=192.168.0.100 offset=-0.0011111111 16040448399870809

```

In order to test what’s wrong return a static string, like the one above, or even a simpler one, also remember that exec uses cmd to call powershell, and sometimes this causes issues

To test the script call it from cmd manually `powershell -file _fileName_` or `powershell -command _fileName_`. there is a difference between the two, but it has been a while since I did some scripts and I don’t remember it.  
I’ve had some problems in the past and ended up using `Write-Output` instead of `Write-Host` because in some cases cmd was “losing” characters.

To ensure what’s being outputted to influxDB you can also set up an [output file](https://github.com/influxdata/telegraf/tree/master/plugins/outputs/file) in order to have the actual line protocol strings you are producing

here are some older posts about PowerShell that might help you:

> [@Inputs.exec with Powershell](https://community.influxdata.com/t/inputs-exec-with-powershell/12710):
>
> I’m having troubles within my telegraf.conf file using the inputs.exec method to call on my powershell script to check the status of DFSR between nodes. I have a simple powershell script that when ran on its own returns the results using write-host PS C:\Program Files\Telegraf\> C:\dfsr.ps1 DFSRBacklog,host=DFS1, DfsrBacklogCount=0i My telegraf.conf file [[inputs.exec]] commands = [“powershell C:/dfsr.ps1”] timeout = “5s” name\_suffix = “\_mycollector” data\_format = “influx” When I try…

> [@Inputs Exec Powershell](https://community.influxdata.com/t/inputs-exec-powershell/12417):
>
> Hi, I’ve a powershell script for dhcp scopes. It’ll return output like below: scope id, free, reserved, inuse It’ll return 1 row for each scope id and scope id will be a tag and there are 3 measurements. How should I configure telegraf and edit script accordingly? Thanks,

---

<div class="post-metadata">

**Author:** ![ptica](https://avatars.discourse-cdn.com/v4/letter/p/5f9b8f/32.png) [@ptica](https://community.influxdata.com/u/ptica)\
**Post date:** [October 30, 2020, 10:41am UTC](https://community.influxdata.com/t/telegraf-inputs-exec-formatting-windows-powershell/16527/3 "2020-10-30T10:41:31Z")

</div>

Thanks for the recommendation. Running the script under cmd returns same result. My main concern is why I’m getting the measurement name offset attached to time.stats. I was expecting it to look more like time.stats.offset.

---

<div class="post-metadata">

**Author:** ![Giovanni\_Luisotto](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/giovanni_luisotto/32/4017_2.png) [@Giovanni\_Luisotto](https://community.influxdata.com/u/Giovanni_Luisotto)\
**Post date:** [October 30, 2020, 10:46am UTC](https://community.influxdata.com/t/telegraf-inputs-exec-formatting-windows-powershell/16527/4 "2020-10-30T10:46:16Z")

</div>

I can’t really help since I don’t know the script, I’d set-up an output file in telegraf. Write your data there and into InfluxDB, in case of errors, InfluxDB will throw errors and you won’t see the points, but the output file will have them all. from there you can check what went worng
