Getting Data In

Restarting Splunk Forwarders with Powershell

zacharyhatsis
New Member

Can anyone give me some insight into why this script might not be working? I'm fairly new to powershell, so i'm sure its somethign simple:

$serverlist =
"C:\Users\zh\Desktop\serverlist.txt"
Get-Content $serverlist |
foreach($comp in
$serverlist){Invoke-Command
-ComputerName $_ -FilePath "C:\Program Files\SplunkUniversalForwarder\bin\splunk.exe"
-ArgumentList restart -verbose}

I tried using the splunk powershell kit, and didn't have a lot of luck getting the commands to work without debugging it, so I figured this shoudl be a simple one-liner on powershell to fix on my own rather than debugging the kit. Thanks!

Tags (1)
0 Karma

bdlabs
Splunk Employee
Splunk Employee

Try "restart-service splunk*" instead of "-FilePath "C:Program FilesSplunkUniversalForwarderbinsplunk.exe"
-ArgumentList restart -verbose"

zacharyhatsis
New Member

$serverlist = "C:\Users\zh\Desktop\serverlist.txt"
foreach ($server in Get-Content $serverlist) {Invoke-Command -ScriptBlock {"C:\program files\splunkuniversalforwarder\bin\splunk.exe restart"} -ComputerName $server -verbose}

0 Karma

sbrant_splunk
Splunk Employee
Splunk Employee

FYI, you can either escape the slashes in your answer or highlight the "code" portion of your answer and click the "code sample" (1s and 0s) button on the formatting menu.

zacharyhatsis
New Member

for some reason the backslashes get removed from this thread. they are all there for the directory names.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...