Splunk Search

Extract specific data from logs.

aikn061
Explorer

Hello,  

I need help with extracting specific data from logs.  I know this has been discussed few times before but if anyone has worked on powershell logs, you will see that it comes with lot of data.  Even doing simple get process at shell gives you information like below(example1)and scripts and other more complicated commands give lot more data(example2).  

What I want to do it only display the commands that were run.  Meaning, extract just the commands in below text and disaplay as table or list in splunk.  How do I do this?  I already have regex that will catch powershell's verb-noun combo like this - [a-zA-Z]{3,}-[a-zA-Z]{3,} - this will match any powershell command.  But how do I extract just the command from lot of junk and display only PS commands and its switches and values? 

 

Example 1)  Creating Scriptblock text (1 of 1):  get-process -Name explorer.exe

ID: abc1234-8539-44xy-a16d-0492bfbd0d61 Path:

 

Exmaple2)

Creating Scriptblock text (1 of 1):  

For ($x in $y) {

get-process -Name Explorer.exe

write-host $x 

}

ID: abc1234-8539-44xy-a16nn-0492mnod0d61 Path:

Labels (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @aikn061,

could you highlight the part of logs to extract?

Ciao.

Giuseppe

0 Karma

aikn061
Explorer

sure thing.  In red and bold is only thing I want to extract and display in splunk table or list.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @aikn061,

you have to use two different regexes for the two examples.

Example 1:

| rex "\):\s+(?<command1>.*)\s+ID"

Example2.

| rex "\{(?<prog2>[^\}]*)"

Ciao.

Giuseppe

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...