Take the output string from BASH or PowerShell command and save it as a variable

Tags:

#1 casey1234

Hi,

It's basically what the title implies.

I want to run a command that produces a string and save it as a variable to be used later in various output blocks. So far the command is working and I can send the output to a om_file logfile but I don't know how to assign the value to a variable to be used elsewhere in the config.

<Input powershell>
    Module  im_exec
    Command "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    Arg     "$IP = Get-WmiObject  Win32_NetworkAdapterConfiguration | where {$_.IPEnabled};$IP.DefaultIPGateway"
    <Exec>
        parse_json();
        $EventTime = parsedate($EventTime);
    </Exec>
</Input>

Thanks!!

#2 casey1234
#1 casey1234
Hi, It's basically what the title implies. I want to run a command that produces a string and save it as a variable to be used later in various output blocks. So far the command is working and I can send the output to a om_file logfile but I don't know how to assign the value to a variable to be used elsewhere in the config. <Input powershell> Module im_exec Command "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" Arg "$IP = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.IPEnabled};$IP.DefaultIPGateway" <Exec> parse_json(); $EventTime = parsedate($EventTime); </Exec> </Input> Thanks!!

This was the answer at least for me:

<Input powershell>
    Module  im_exec
    Command "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    Arg     "$IP = Get-WmiObject  Win32_NetworkAdapterConfiguration | where {$_.IPEnabled};$IP.DefaultIPGateway"
    <Exec>
       $gateway = $raw_event;
    </Exec>
</Input>