<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PowerShell script through inputs.conf in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144373#M29491</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;powershell is a mess with splunk and you have to create a .path file..  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;inputs.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://.\bin\myscript.path]
interval=300
disabled=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;myscript.path&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe -command  " &amp;amp;'$SPLUNK_HOME\etc\apps\myapp\bin\powershell\myscript.ps1'"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Andreas&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jun 2015 13:48:13 GMT</pubDate>
    <dc:creator>schose</dc:creator>
    <dc:date>2015-06-08T13:48:13Z</dc:date>
    <item>
      <title>PowerShell script through inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144372#M29490</link>
      <description>&lt;P&gt;I am trying to get my PowerShell script to be invoked by inputs.conf. My PowerShell script, ScriptTest.ps1, looks like this (borrowed)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Get-Process  | Where-Object {$_.ws -gt 0MB} | ForEach-Object -Begin {
         $Owner = Get-WmiObject -Class Win32_Process
     } -Process {
         $ID = $_.Id
         New-Object -TypeName 'PSCustomObject' -Property @{
             'UserName' = ($Owner | Where-Object {$_.ProcessID -eq $ID}).GetOwner().User
             'DomainName' = ($Owner | Where-Object {$_.ProcessID -eq $ID}).GetOwner().Domain
             'ProcessName' = $_.ProcessName
             'MemoryUsed' = "{0:N2} MB" -f ($_.WS / 1MB)
         } | Select-Object -Property UserName,DomainName,ProcessName,MemoryUsed
     } | out-file output.txt
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My .cmd file is Status.cmd, and looks like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;@powershell -File H:\MyScripts\ScriptTest.ps1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My inputs.conf looks like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://$SPLUNK_HOME\etc\apps\SA-ModularInput-PowerShell\Status.cmd]
 interval = 0
 sourcetype = winperf
 index = main
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So essentially, I was expecting that when I restarted the service, the output.txt file would be generated. I know the script and command file work because I have ran the command file and the output.txt file was generated. Does anyone know what I am doing incorrectly? Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2015 13:43:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144372#M29490</guid>
      <dc:creator>nce054</dc:creator>
      <dc:date>2015-06-08T13:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: PowerShell script through inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144373#M29491</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;powershell is a mess with splunk and you have to create a .path file..  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;inputs.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://.\bin\myscript.path]
interval=300
disabled=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;myscript.path&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe -command  " &amp;amp;'$SPLUNK_HOME\etc\apps\myapp\bin\powershell\myscript.ps1'"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Andreas&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2015 13:48:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144373#M29491</guid>
      <dc:creator>schose</dc:creator>
      <dc:date>2015-06-08T13:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: PowerShell script through inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144374#M29492</link>
      <description>&lt;P&gt;That seemed to work once, but I deleted the output file that my script was creating, and now it isn't recreating it. I've restarted the service on the Universal Forwarder multiple times. Does the interval of 300 mean that it will take 5 minutes to create the first output file?&lt;/P&gt;

&lt;P&gt;EDIT: I see talk of if a process doesn't end, Splunk won't run it again. How can I tell if the script ran completely? Isn't the fact that the output file was generated proof of that?&lt;/P&gt;

&lt;P&gt;EDIT: I looked into splunkd.log, and I see that it tried to run the script and exited with the error code 255. Looking into it.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2015 14:27:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144374#M29492</guid>
      <dc:creator>nce054</dc:creator>
      <dc:date>2015-06-08T14:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: PowerShell script through inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144375#M29493</link>
      <description>&lt;P&gt;300 means the script will run every 5 minutes or if forwarder will be restarted. Check SPLUNK_HOME/var/log/splunk/splunkd.log. script errors of your powershellscript will be displayed there. notice that your powershell script is running in context of the forwarders user (default: system). try to run the script manually to troubleshoot.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2015 14:41:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144375#M29493</guid>
      <dc:creator>schose</dc:creator>
      <dc:date>2015-06-08T14:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: PowerShell script through inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144376#M29494</link>
      <description>&lt;P&gt;Ran script manually without issue. Trying to think of what could be causing the problem.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2015 14:47:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144376#M29494</guid>
      <dc:creator>nce054</dc:creator>
      <dc:date>2015-06-08T14:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: PowerShell script through inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144377#M29495</link>
      <description>&lt;P&gt;Issue resolved, was having a problem with where I was keeping my script, it wanted it with all of the other scripts in &lt;CODE&gt;$SPLUNK_HOME\bin\scripts&lt;/CODE&gt;. Thanks for the help, schose!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2015 15:50:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144377#M29495</guid>
      <dc:creator>nce054</dc:creator>
      <dc:date>2015-06-08T15:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: PowerShell script through inputs.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144378#M29496</link>
      <description>&lt;P&gt;The answer above didn't help me when I found it via Google. A Stackoverflow answer led me in the right direction.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;powershell -noexit "&amp;amp; ""C:\my_path\yada_yada\run_import_script.ps1""" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/2035193/how-to-run-a-powershell-script"&gt;http://stackoverflow.com/questions/2035193/how-to-run-a-powershell-script&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Referencing the path to Powershell is usually unnecessary. Using a variable for the Splunk install location also might be unnecessary. Regardless of a 32/64 bit installation, it should always bee under &lt;CODE&gt;C:\Program Files&lt;/CODE&gt;. As for drive letter, the average user doesn't install programs to drives other than where Windows is installed, and Windows is almost always installed on &lt;CODE&gt;C:&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 19:02:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/PowerShell-script-through-inputs-conf/m-p/144378#M29496</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-04-05T19:02:23Z</dc:date>
    </item>
  </channel>
</rss>

