The below powershell script will use the commandline tool "sc.exe" to output the service name and status, and then format the results with a simple echo output so Splunk can read it as an input.
$output = sc.exe query state= all
$formatted = new-object PSObject
for ($i=0; $i -lt $output.Length; $i++) {
if ($output[$i] -like "SERVICE_NAME:*") {
$service = $output[$i] -replace 'SERVICE_NAME: ',''
$status = $output[$i+3] -replace ' STATE : ',''
$status = $status -replace ' ',','
$newout = $service + "," + $status
echo $newout
}
}
Sample results:
smphost,1,STOPPED
SmsRouter,1,STOPPED
smstsmgr,1,STOPPED
SNMPTRAP,1,STOPPED
SplunkForwarder,4,RUNNING
Spooler,4,RUNNING
sppsvc,4,RUNNING
... View more