Telegraf loop in powershell script only executes one time

I am using this small powershell script to extract some info of the current network-adapters on a windows host. If I run the script manually I get one POST for each network-adapter inserted in the influxdb.
But when I run the same script from telegraf the script only posts the first result.

Function StatusReplace($status) {
     switch ($status)
    {
    "Disconnected" { 1 }
    "Up" { 0 }
    default { 2 }
    }
}

Get-NetAdapter | Select-Object "InterfaceDescription", "Status", "LinkSpeed" | %{

$data="win_networkadapters,host=$env:computername,interface=$($_.InterfaceDescription -replace ' ', '\ '),linkspeed=$($_.LinkSpeed -replace ' ', '\ '),connection=$($_.Status -replace ' ', '\ ') status=$(StatusReplace($_.Status))"
Invoke-WebRequest -Uri "http://<Server>:8086/write?db=telegraf" -Method POST -Body $data
}

telegraf.conf

[[inputs.exec]]
  interval = "1m"
  commands = [ "powershell C:/Temp/getNetworkadapterInfo.ps1" ]
  timeout = "20s"
  data_format = "influx"

Ah, I just write-host and telegraf handles the insertion into the database. No need for posting :slight_smile:

Write-Host works, the invoke web method will work but you might need to wrap it in a for each loop.

For readability, personally i would clean the data (these sections (_.LinkSpeed -replace ’ ', '\ ')) before passing the data to Telegraf. but thats just personal preference i guess