Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get first value after Where-Object condition

Tags:

powershell

Give the following command how to get only the first value after the where condition?

Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} |
  select id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Value}} |
  where USER -notlike 'condition'

I tried -MaxEvents 1 and -First 1 but that applies only to Select-Object, doesn't work with where.

like image 861
Hélder Portela Avatar asked Jun 14 '26 16:06

Hélder Portela


1 Answers

Pipe your results to Select-Object -First 1 like so:

Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} |
  Select-Object Id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Value}} | 
  Where-Object { $_.USER -notlike 'condition' } |
  Select-Object -First 1
like image 161
Bender the Greatest Avatar answered Jun 17 '26 13:06

Bender the Greatest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!