Author Posts

January 6, 2017 at 11:01 pm

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
}

January 6, 2017 at 11:29 pm

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
}

January 7, 2017 at 12:29 am

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