0

I am trying to filter the results of the logman command using powershell. I’ve tried to select a single property, filter using where-object, but it seems like the results from logman (stored in an array) are not accessible via their properties. Here are some commands I have tried so far:

logman -ets query #returns result

logman -ets query | select-object #returns result

logman -ets query | select-object -first 10 -Property Status #nothing

logman -ets | where-object {$_.Status -eq "Running"} #nothing

logman -ets | where-object {$_.Status -eq "Running"} #nothing

logman -ets | where-object {$_.Status -gt "R"} -debug #nothing

I am hoping to filter out just those sessions that pertain to my local service fabric emulator so I can get a handle on where my various service fabric logs are stored.

Any thoughts?

Adam P
  • 129
  • 1
  • 1
  • 11
  • 2
    You cannot use Select-Object because you don't have any object. You will have to parse the text output logman produces. – Olaf Aug 26 '19 at 16:15
  • What does the output look like? – js2010 Aug 26 '19 at 17:00
  • The output of the command appears like this: (I'm not sure how to paste code in a comment - so this is garbled... The output is a header row, followed by dashes, followed by what appears to be columns of data, one column for each header. ` Data Collector Set Type Status ------------------------------------------------------------------------------- Circular Kernel Context Logger Trace Running AppModel Trace Running ` – Adam P Aug 27 '19 at 18:23

1 Answers1

3

logman, being an "external" command (one implemented as a .EXE file, rather than a PowerShell cmdlet), does not generate Objects within the meaning of the term in PowerShell. Instead, it generates a text stream, which you will have to parse. From the looks of it, the status is the last eight characters of the line, so you'll need to do something like

logman -ets query | Where-Object {-join $_[-8..-1] -eq "Running "}
Jeff Zeitlin
  • 9,773
  • 2
  • 21
  • 33
  • I see what you are saying. I was thrown off because the "text" output of the logman exe command appears to be that which would be outputted by a normal powersell command. So, I incorrectly assumed it was. With this knowledge, I should be able to write a wrapper for this in c# which preforms the action in a normal "powershell" way. Thank you! – Adam P Aug 27 '19 at 18:22