Optimizing Command-Line

Welcome Forums General PowerShell Q&A Optimizing Command-Line

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 1 month ago.

  • Author
  • #23487

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

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


  • #23488

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Optimizing Command-Line’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort