<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Separate PowerShell Objects with / for search in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641720#M109419</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;ITWhisperer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Such a complicated query monster? I hoped for an easy to understand solution.&lt;BR /&gt;I think the parsing cost for such a query are very high on Server or not?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I give it a try....&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Apr 2023 07:03:42 GMT</pubDate>
    <dc:creator>pamkkkkk</dc:creator>
    <dc:date>2023-04-28T07:03:42Z</dc:date>
    <item>
      <title>How to separate PowerShell objects with / for search?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641710#M109417</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I have written a PowerShell Script to obtain Hard-Disk Informations for Local Drives and report it to Splunk.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;If(Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) {
    $Drives = Get-CimInstance -Query 'SELECT * FROM Win32_LogicalDisk WHERE DriveType=3' -QueryDialect 'WQL'
} Else {
    $Drives = Get-WmiObject -Query 'SELECT * FROM Win32_LogicalDisk WHERE DriveType=3'
}

$Drives | ForEach-Object {
    $Drive = $_ | Select-Object FreeSpace,Size,FileSystem,VolumeSerialNumber,PercentFree,UsedGB,FreeGB,@{Name='DriveLetter';Expression={ $_.DeviceID }},IsSystemdrive
    $Drive.PercentFree = [Math]::Round(($Drive.FreeSpace / $Drive.Size * 100),2)
    $Drive.UsedGB = [Math]::Round((($Drive.Size - $Drive.FreeSpace) / 1GB),2) 
    $Drive.FreeGB = [Math]::Round(($Drive.FreeSpace / 1GB),2)
    If($Drive.DriveLetter -eq $env:SystemDrive) {
        $Drive.IsSystemdrive = $true
    } Else {
        $Drive.IsSystemdrive = $false
    }
    $Drive
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gives me&amp;nbsp; the following result in Splunk for a System&amp;nbsp; with Harddisk C and D&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;FreeSpace          : 37910388835
Size               : 106847793152
FileSystem         : NTFS
VolumeSerialNumber : 64A9A098
PercentFree        : 53,54
UsedGB             : 46,23
FreeGB             : 53,28
DriveLetter        : C:
IsSystemdrive      : True
FreeSpace          : 27610488832
Size               : 268432306176
FileSystem         : NTFS
VolumeSerialNumber : E2651A32
PercentFree        : 10,29
UsedGB             : 224,28
FreeGB             : 25,71
DriveLetter        : D:
IsSystemdrive      : False&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My Query skills are not the best ... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How can I separate the PowerShell objects (Disk C: and D:) in a query?&lt;BR /&gt;For example; To monitor the system drive only?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This discussion is for learning, how to parse such PowerShell objects.&lt;BR /&gt;Not to use other workarounds.)&lt;/P&gt;
&lt;P&gt;I'm also grateful if someone has tips on how to better prepare (separate) the PowerShell objects for Splunk searches.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 13:42:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641710#M109417</guid>
      <dc:creator>pamkkkkk</dc:creator>
      <dc:date>2023-04-28T13:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Separate PowerShell Objects with / for search</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641717#M109418</link>
      <description>&lt;P&gt;You could try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex max_match=0 "(?&amp;lt;name&amp;gt;\w+)\s+:\s(?&amp;lt;value&amp;gt;.+)"
| streamstats count as event
| eval count=mvcount(name)
| eval row=mvrange(0,count)
| mvexpand row
| eval name=mvindex(name,row)
| eval value=mvindex(value,row)
| eval {name}=value
| fields - name value _raw row count
| stats list(*) as * by event
| eval drive=mvcount(DriveLetter)
| eval row=mvrange(0,drive)
| mvexpand row
| rename row as _row
| rename event as _event
| foreach *
    [| eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=mvindex(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,_row)]
| rename _event as event&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 06:55:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641717#M109418</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-28T06:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Separate PowerShell Objects with / for search</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641720#M109419</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;ITWhisperer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Such a complicated query monster? I hoped for an easy to understand solution.&lt;BR /&gt;I think the parsing cost for such a query are very high on Server or not?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I give it a try....&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 07:03:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641720#M109419</guid>
      <dc:creator>pamkkkkk</dc:creator>
      <dc:date>2023-04-28T07:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Separate PowerShell Objects with / for search</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641730#M109420</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/256284"&gt;@pamkkkkk&lt;/a&gt; , you could also try the following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex max_match=0 "(?msi)(?&amp;lt;raw&amp;gt;FreeSpace.+?IsSystemdrive\s+:\s+\w+)\s*"
| fields - _raw | mvexpand raw
| rex field=raw mode=sed "s/ //g"
| rex field=raw mode=sed "s/\n/ /g"
| rename raw as _raw
| extract pairdelim=" " kvdelim=":"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I tested it and the output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="javiergn_0-1682668897624.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/25137i717CD820E9D537AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="javiergn_0-1682668897624.png" alt="javiergn_0-1682668897624.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you write your PS output already in key=value pairs (or key:value, or any other delimiter) it'll be easier to extract than multiline and a lot cheaper from a performance point of view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;J&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 08:03:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-separate-PowerShell-objects-with-for-search/m-p/641730#M109420</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2023-04-28T08:03:06Z</dc:date>
    </item>
  </channel>
</rss>

