Get-WinEvent will not display computer name!

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Kraze Kraze 6 months, 2 weeks ago.

  • Author
    Posts
  • #61462
    Profile photo of Kraze
    Kraze
    Participant

    I am using the below script to query the event log of remote computers and spit out a specific event. The script works pretty much perfectly, but it doesn't display the computer name an event is from. This is obviously problematic when checking against 100 host. I am struggling considerably to correct this behavior, can anyone help me achieve this?

    $ServerName = Get-Content "Computers.txt"
    $time = (Get-Date) - (New-TimeSpan -Day 120)
    $currnet = (Get-Date)
    
    foreach ($Server in $ServerName) {
    
    Get-WinEvent @{logname='Application'; level=2,3;starttime=$time;providername='IAStorDataMgrSvc'} -ErrorAction SilentlyContinue -ComputerName $Server
    }
  • #61465
    Profile photo of random commandline
    random commandline
    Participant

    You have to select the 'machinename' property.

    foreach ($Server in $ServerName) {
    Get-WinEvent @{logname='Application'; level=2,3;starttime=$time;providername='IAStorDataMgrSvc'} -ErrorAction SilentlyContinue -ComputerName $Server | Select-Object machinename,timecreated,id,leveldisplayname,message
    }
    
  • #61470
    Profile photo of Kraze
    Kraze
    Participant

    That did exactly what I needed it too. Thank you very much!

You must be logged in to reply to this topic.