All Apps and Add-ons

PowerShell Modular input doesn't process my sourcetype for the data.

axl88
Communicator

I had a scripted input with power-shell as simply, *.bat files pointing to *.ps1 files and I was able to use my sourcetype by inputs.conf and props.conf.
We recently upgraded our system to Splunk 6.3 and decided to user PowerShell Modular input from UI since we would have a chance to edit schedules without restarting system etc..
Although, it is the same same power-shell script and props.conf, Splunk indexer fails to set sourcetype to my predefined type although I pick my source-type from the list. Instead, each time I save from UI as "from the list", whenever I go back to modular input page, it says manual and simply breaking my event into line by line.
Please advise as this is a bug for Splunk PowerShell modular input or I am missing something in the process?
Thanks upfront for your time.

0 Karma
1 Solution

jkat54
SplunkTrust
SplunkTrust

According to the documentation you should be formatting your output differently when using in conjunction with modular input and powershell app.

http://docs.splunk.com/Documentation/AddOns/latest/MSPowerShell/Writescriptsforthemodularinput#Outpu...

Important: The modular input currently requires that any PowerShell scripts it executes produce output objects that do not have any script properties. Pipe output through | Select-Object * to ensure proper formatting.

 $Directories = @("c:\test","c:\windows")
 $now = $(get-date).ToString()

 foreach ($item in $Directories){
         $directoryInfo = $(Get-ChildItem $item -ErrorAction silentlycontinue| Measure-Object).Count
         $howManyDirectories = $(Get-ChildItem $item -ErrorAction silentlycontinue | where {$_.PSIsContainer} | Measure-Object).Count
         $howManyFiles = $(Get-ChildItem c:\ -ErrorAction silentlycontinue | where {$_.mode -notlike "d*"} | Measure-Object).Count
         if(!(Test-Path -Path $item )){
             write-output( $now + " no directory " + $item) | Select-Object *

         }
         elseif($directoryInfo -eq $directoryInfo){
             write-output($now + " " +$item + $onlyDirectory) | Select-Object *
             #I really dont understand this elseif and it's purpose  I have dir with one sub dir and it always gets stuck here.
         }
         else {
             $date = (Get-Date).AddHours(-4)
             write-output $((get-childitem $item | where-object {$_.LastWriteTime -lt $date -and !$_.PSIsContainer}| foreach-object { Write-Output $now " File: " $_.FullName " LastWriteTime: " $_.LastWriteTime | Select-Object *}))

         }
 }

You'll note I scratched your echos and same error handling variables you had and I dont understand the elseif. I think its meant to be if the directory is empty. I made you variables in your foreach equal to numbers instead of arrays with numbers attached which simplifies their usage later. Biggest point to get across here is the usage of the |select-object *

View solution in original post

Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...