To demonstrate this the code example below will
- Query the application event log of a remote server
- Order the log entries by the date they occurred
- Return the first 5 results from the set
The cmdlet Get-WmiObject is the gateway to WMI and allowed me to complete the first step with this simple command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$e = get-wmiobject -computerName 'SERVER' -query "SELECT * FROM Win32_NTLogEvent WHERE (logfile='application') AND (type='warning')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$e | Where { $_.Message -match "websitename" } | Select * -First 5 | Sort TimeGenerated -desc | fl |
The big win here is being able to run a query on a remote server but manipulate the result set on my local machine. WMI has a large set of providers which are now only a query away from my console.