Splunk SOAR (f.k.a. Phantom)

Splunk Soar - Windows Remote Management - Custom Code in Run Script Shape

whill
New Member

Hello,

I'm trying to utilize the following script (at the bottom) in the 'Run Script' shape in the Windows Remote Management app in Splunk Soar. This shape errors out due to curly braces used in the while loop and if statement along with the parameter {0} which will represent a Windows service. 

What are my options to get around the use of this curly brace? I've thought about using the custom code section, but I'm unsure how to set the script_str parameter without touching non-custom code. Attached is a screenshot detailing what I have with the custom code idea.

2023-04-05 15_17_55-PB _ Windows Restart Service.png

Script to verify the status of a Windows service, looping to check every 30 seconds for 15 minutes:

$timeout = new-timespan -Minutes 15
$sw = [diagnostics.stopwatch]::StartNew()
$status
$success=0
while ($sw.Elapsed -lt $timeout -AND $success -eq 0){
$status = Get-Service "{0}" | select -ExpandProperty status
if ($status -contains "Stopped"){
$success = 1
}
start-sleep -seconds 30
}
write-output $success

Labels (2)
0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...