Link to home
Create AccountLog in
Avatar of compdigit44
compdigit44

asked on

Get-Eventlog Script to list Application & System log on Multiple Servers

I'm trying to write a powershell script that queries a handfull of servers event logs Application & System's  with an event of Warning or Error and dump them to a text file and email it to me.

From example, I tried using  the following and the error I get states the LogName can only specify one log at a time.......

Get-Eventlog -LogName Application, System -EntryType Warning, Error

I'm still trying to learn powershell of your hepl is greatly appreachiated.
Avatar of sfossupport
sfossupport
Flag of United States of America image

Here is an example of querying eventlog. These guys are very helpful. After you get one
to work you can create a list of servers and access these

http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/29/use-powershell-to-perform-offline-analysis-of-security-logs.aspx
Avatar of compdigit44
compdigit44

ASKER

Thanks, I read throught the article and I'm trying to type in the following syntax on two seperate lines yet it gives me an error stating the -LogName is not in the correct format.  I also tried to place the $Logs name and pipe it to the get-eventlog cmdlet on the same line and it did work either.

$Logs = "system","application"
Get-EventLog -LogName $Logs -EntryType warning,error -Newest 20
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks, as a test I saved the following in notepad and saved the file as somethin.ps1

[Array]$Logs = $null
$logs += Get-EventLog -LogName application -EntryType warning,error -Newest 20
$logs += Get-EventLog -LogName system -EntryType warning,error -Newest 20

I checked the script using the PowerShell ISE and not errors were detected yet when the script runs nothing is displayed on script. The script just returns to the command prompt.
The result is saved in var $logs like I mentioned either you can export it to .csv using Export-Csv

$Logs | Export-Csv test.csv -NoTypeInformation

or just add $logs at the end to display the result..
Perfect I got it now... THANKS!!!