简体   繁体   中英

Select Top 5 or Limit to 5 entries on Get-WmiObject Powershell query

I'm perfoming queries on the event viewer (Win32_NTLogEvent) Is there anyway to just select the top 10 or max 5 return events

I had already try with TOP , LIMIT or ROWCOUNT but nothing works

Get-WmiObject -Query 'SELECT * FROM Win32_NTLogEvent WHERE (SourceName = "Microsoft-Windows-Kernel-Power" and EventCode = "41")'

WQL doesn't support the TOP , LIMIT or ROWCOUNT keywords; instead, you'll need to pipe the results to the Select-Object cmdlet and select the -First 10 rows, eg:

Get-WmiObject -Query 'SELECT * FROM Win32_NTLogEvent WHERE (SourceName = "Microsoft-Windows-Kernel-Power" and EventCode = "41")' | select -First 10

You may also need to pipe the results through the Sort-Object cmdlet first, so that the results are sorted by a given property prior to selection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM