Get-WinEvent will not display computer name!

Welcome Forums General PowerShell Q&A Get-WinEvent will not display computer name!

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

 
Participant
1 year, 11 months ago.

  • Author
    Posts
  • #61462

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 10
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

The topic ‘Get-WinEvent will not display computer name!’ is closed to new replies.