Optimizing Command-Line

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 8 months ago.

  • Author
    Posts
  • #23487
    Profile photo of Bart Donders
    Bart Donders
    Participant

    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 }}}

    Regards,
    Bart

  • #23488
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

You must be logged in to reply to this topic.