<?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: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed? in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242786#M27500</link>
    <description>&lt;P&gt;Example 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = 'C:\Program Files\SplunkUniversalForwarder\bin\splunk.exe'
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "list forward-server"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
Write-Host "stdout: $stdout"
Write-Host "stderr: $stderr"
Write-Host "exit code: " + $p.ExitCode
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 2:&lt;BR /&gt;
        `add-type @"&lt;BR /&gt;
        using System.Net;&lt;BR /&gt;
        using System.Security.Cryptography.X509Certificates;&lt;BR /&gt;
        public class TrustAllCertsPolicy : ICertificatePolicy {&lt;BR /&gt;
            public bool CheckValidationResult(&lt;BR /&gt;
                ServicePoint srvPoint, X509Certificate certificate,&lt;BR /&gt;
                WebRequest request, int certificateProblem) {&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;BR /&gt;
    "@&lt;BR /&gt;
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$user = "admin"
$pass = convertto-securestring -AsPlainText -Force -String 'admin' #your password here
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$pass
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/default" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/default&lt;/A&gt; -credential $cred
$request.Content
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/group" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/group&lt;/A&gt; -credential $cred 
$request.Content
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/server" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/server&lt;/A&gt; -credential $cred 
$request.Content
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/allconnections" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/allconnections&lt;/A&gt; -credential $cred 
$request.Content`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 3:&lt;BR /&gt;
&lt;A href="http://dev.splunk.com/view/splunk-powershell-resource-kit/SP-CAAADRU"&gt;http://dev.splunk.com/view/splunk-powershell-resource-kit/SP-CAAADRU&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 16 May 2016 10:56:05 GMT</pubDate>
    <dc:creator>jkat54</dc:creator>
    <dc:date>2016-05-16T10:56:05Z</dc:date>
    <item>
      <title>How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242780#M27494</link>
      <description>&lt;P&gt;I want to find a script to list splunk forwarder status the restart the service if the listing failed.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$serverlist =
"C:\serverlist.txt"
Get-Content $serverlist |
foreach($comp in
$serverlist){Invoke-Command
-ComputerName $_ -FilePath "C:\Program Files\SplunkUniversalForwarder\bin\splunk.exe"
-ArgumentList splunk list forward-server}
Or
$sstat = Get-Service -Name splunkd
#Checks for Service Status
#Restarts Splunk Service if it's running, or starts if it is stopped
if ($sstat.status -eq "running"){
    write-output "Restarting Splunk"
    restart-service splunkd
    }
elseif ($sstat.status -eq "stopped"){
    start-service splunkd
    write-output "Splunk is starting"
    }
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 May 2016 03:07:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242780#M27494</guid>
      <dc:creator>ginger8990</dc:creator>
      <dc:date>2016-05-11T03:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242781#M27495</link>
      <description>&lt;P&gt;Splunk community is not good as spicework community, no one ever reply the Q&amp;amp;A.&lt;/P&gt;

&lt;P&gt;Let me put this way: Splunk commands can support powershell? Such as splunk list forward-server is not recognized in Powershell.&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 15:29:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242781#M27495</guid>
      <dc:creator>ginger8990</dc:creator>
      <dc:date>2016-05-12T15:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242782#M27496</link>
      <description>&lt;P&gt;I downvoted this post because &lt;A href="http://lmgtfy.com/?q=splunk+powershell"&gt;http://lmgtfy.com/?q=splunk+powershell&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 15 May 2016 23:02:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242782#M27496</guid>
      <dc:creator>piebob</dc:creator>
      <dc:date>2016-05-15T23:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242783#M27497</link>
      <description>&lt;P&gt;Seriously... This is a loaded question.  Have you ever done powershell remoting?  Will you enable WinRM or use WMI? Do you know what each entails?  Are you paying for the development and subsequent deployment?  Or do you just expect someone to spend the next month here explaining it to you?  It's hard enough to enable WinRM and double hop code execution in your own environment; let alone explain it to someone else...&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 00:36:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242783#M27497</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-16T00:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242784#M27498</link>
      <description>&lt;P&gt;I share code here all the time but I don't have it in me to go into the intracacies of remote code execution in a windows environment.  I'll do better by you letting you figure it out yourself anyways.  I think I gave enough hints by now. Best of luck.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 00:43:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242784#M27498</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-16T00:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242785#M27499</link>
      <description>&lt;P&gt;your answer is not splunk powershell related.&lt;/P&gt;

&lt;P&gt;What you are talking about is prerequisite  of using powershell...........how to you use powershell without prerequisite?&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 03:47:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242785#M27499</guid>
      <dc:creator>ginger8990</dc:creator>
      <dc:date>2016-05-16T03:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242786#M27500</link>
      <description>&lt;P&gt;Example 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = 'C:\Program Files\SplunkUniversalForwarder\bin\splunk.exe'
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "list forward-server"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
Write-Host "stdout: $stdout"
Write-Host "stderr: $stderr"
Write-Host "exit code: " + $p.ExitCode
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 2:&lt;BR /&gt;
        `add-type @"&lt;BR /&gt;
        using System.Net;&lt;BR /&gt;
        using System.Security.Cryptography.X509Certificates;&lt;BR /&gt;
        public class TrustAllCertsPolicy : ICertificatePolicy {&lt;BR /&gt;
            public bool CheckValidationResult(&lt;BR /&gt;
                ServicePoint srvPoint, X509Certificate certificate,&lt;BR /&gt;
                WebRequest request, int certificateProblem) {&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;BR /&gt;
    "@&lt;BR /&gt;
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$user = "admin"
$pass = convertto-securestring -AsPlainText -Force -String 'admin' #your password here
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$pass
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/default" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/default&lt;/A&gt; -credential $cred
$request.Content
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/group" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/group&lt;/A&gt; -credential $cred 
$request.Content
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/server" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/server&lt;/A&gt; -credential $cred 
$request.Content
$request = Invoke-WebRequest -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/allconnections" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/allconnections&lt;/A&gt; -credential $cred 
$request.Content`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 3:&lt;BR /&gt;
&lt;A href="http://dev.splunk.com/view/splunk-powershell-resource-kit/SP-CAAADRU"&gt;http://dev.splunk.com/view/splunk-powershell-resource-kit/SP-CAAADRU&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 10:56:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242786#M27500</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-16T10:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242787#M27501</link>
      <description>&lt;P&gt;Hey spice works guy... I have answer and you no reply for more than 1 day.   Wassup?   &lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 02:24:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242787#M27501</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-18T02:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a PowerShell script to list forwarder status, then restart the service if the listing failed?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242788#M27502</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;$user = "admin" 
$pass = convertto-securestring -AsPlainText -Force -String 'admin' #your password here 
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$pass 
$request = Invoke-RestMethod -uri &lt;A href="https://localhost:8089/services/data/outputs/tcp/server" target="test_blank"&gt;https://localhost:8089/services/data/outputs/tcp/server&lt;/A&gt; -credential $cred 
$request.title
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2016 12:51:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-create-a-PowerShell-script-to-list-forwarder-status-then/m-p/242788#M27502</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-26T12:51:23Z</dc:date>
    </item>
  </channel>
</rss>

