Optimizing Command-Line

Hi all,

I hope you want to take time to have a look at a oneliner I created…

Purpose of this line is to get the latest error and warning messages in the System and Application log of a remote server.

My question is if this syntax I needed can be modified to make it more performing, readable and so on… Are other other ways to get the same results…

The syntax:

icm -Session (Get-PSSession) { Foreach ($item in @("Error", "Warning")) { ( Foreach ($log in @("System", "Application")) { Get-Eventlog -Newest 10 -Entrytype $item -Logname $log }}}


You could definitely use full command names, instead of aliases, to make it a lot more readable.

I’ve not tested to see which is faster, but you’ve got Get-WinEvent, Get-EventLog (which you used), Get-CimInstance - all of which can access that same data. You’d need to test to see which was faster. Get-CimInstance, for example, could probably do all the filtering in one command, which means you wouldn’t be enumerating as much.