<?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 Getting the error: External search command 'testps' returned error code 1. . in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Getting-the-error-External-search-command-testps-returned-error/m-p/688157#M11488</link>
    <description>&lt;P&gt;I'm trying to run personal scripts in Splunk from a dashboard. I want the dashboard to call a script by user input and then output the script to a table. I'm testing the ability with a Python script that calls a PowerShell script, returns the data to the Python script, and then returns the data to the Splunk dashboard. This is what I have so far:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test_PowerShell.py Python Script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import splunk.Intersplunk
import sys
import subprocess

results,unused1,unused2 = splunk.Intersplunk.getOrganizedResults()

# Define the path to the PowerShell script
ps_script_path = "./Test.ps1"

# Define the argument to pass to the PowerShell script
argument = sys.argv[1]

# Execute the PowerShell script with the argument
results = subprocess.run(['powershell.exe', '-File', ps_script_path, argument], capture_output=True, text=True)

splunk.Intersplunk.outputResults(results)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Page XML:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form version="1.1" theme="dark"&amp;gt;
  &amp;lt;label&amp;gt;Compliance TEST&amp;lt;/label&amp;gt;
  &amp;lt;description&amp;gt;TESTING&amp;lt;/description&amp;gt;
  &amp;lt;fieldset submitButton="false" autoRun="false"&amp;gt;&amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Input Panel&amp;lt;/title&amp;gt;
      &amp;lt;input type="text" token="user_input"&amp;gt;
        &amp;lt;label&amp;gt;User Input:&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;/input&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Script Output&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| script python testps $user_input$ | table field1&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;$earliest$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;$latest$&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test.ps1 PowerShell Script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Write-Host $args[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;commands.conf:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[testps]
filename = Test_PowerShell.py
streaming=true
python.version = python3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;default.meta&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[commands/testps]
access = read : [ * ], write : [ admin ]
export = system

[scripts/Test_PowerShell.py]
access = read : [ * ], write : [ admin ]
export = system&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error I'm getting is the following:&amp;nbsp;External search command 'testps' returned error code 1.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 May 2024 15:05:49 GMT</pubDate>
    <dc:creator>jdhart1312</dc:creator>
    <dc:date>2024-05-21T15:05:49Z</dc:date>
    <item>
      <title>Getting the error: External search command 'testps' returned error code 1. .</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Getting-the-error-External-search-command-testps-returned-error/m-p/688157#M11488</link>
      <description>&lt;P&gt;I'm trying to run personal scripts in Splunk from a dashboard. I want the dashboard to call a script by user input and then output the script to a table. I'm testing the ability with a Python script that calls a PowerShell script, returns the data to the Python script, and then returns the data to the Splunk dashboard. This is what I have so far:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test_PowerShell.py Python Script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import splunk.Intersplunk
import sys
import subprocess

results,unused1,unused2 = splunk.Intersplunk.getOrganizedResults()

# Define the path to the PowerShell script
ps_script_path = "./Test.ps1"

# Define the argument to pass to the PowerShell script
argument = sys.argv[1]

# Execute the PowerShell script with the argument
results = subprocess.run(['powershell.exe', '-File', ps_script_path, argument], capture_output=True, text=True)

splunk.Intersplunk.outputResults(results)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Page XML:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form version="1.1" theme="dark"&amp;gt;
  &amp;lt;label&amp;gt;Compliance TEST&amp;lt;/label&amp;gt;
  &amp;lt;description&amp;gt;TESTING&amp;lt;/description&amp;gt;
  &amp;lt;fieldset submitButton="false" autoRun="false"&amp;gt;&amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Input Panel&amp;lt;/title&amp;gt;
      &amp;lt;input type="text" token="user_input"&amp;gt;
        &amp;lt;label&amp;gt;User Input:&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;/input&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Script Output&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| script python testps $user_input$ | table field1&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;$earliest$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;$latest$&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test.ps1 PowerShell Script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Write-Host $args[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;commands.conf:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[testps]
filename = Test_PowerShell.py
streaming=true
python.version = python3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;default.meta&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[commands/testps]
access = read : [ * ], write : [ admin ]
export = system

[scripts/Test_PowerShell.py]
access = read : [ * ], write : [ admin ]
export = system&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error I'm getting is the following:&amp;nbsp;External search command 'testps' returned error code 1.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 15:05:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Getting-the-error-External-search-command-testps-returned-error/m-p/688157#M11488</guid>
      <dc:creator>jdhart1312</dc:creator>
      <dc:date>2024-05-21T15:05:49Z</dc:date>
    </item>
  </channel>
</rss>

