Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script to export event logs in csv - entire exchnage environment

Posted on 2011-03-16
6
Medium Priority
?
849 Views
Last Modified: 2012-05-11
Hi,

Need a script which exports the even logs to the csv, which holds of all exchange servers ....where as am getting it a txt in below mentioned script.

Need to fetch logs only for previous day/ last 24 hrs...

-=================================
$ExchServer=Get-ExchangeServer
$Date = get-date
 write-output $Date | out-file -filePath “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt” -append

-noClobber
foreach ($server in $ExchServer)
{

    $version = $server.admindisplayversion.Major
    $report = Get-EventLog -logname application -newest 5  | select eventid,EntryType,source,message,timegenerated      
    write-output $server.name | out-file -filePath “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt”

-append -noClobber
    write-output $report| out-file -filePath “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt” -append -noClobber    
 }
======================

0
Comment
Question by:mansoornazar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 35156442
Try the following code...

regards
Prashanth
$ExchServer=Get-ExchangeServer
$Date = get-date
$yesterday= $date.adddays(-1).toshortdatestring()

 write-output $Date | Export-Csv “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt” -append

-noClobber
foreach ($server in $ExchServer)
{
    $version = $server.admindisplayversion.Major
    $report = Get-EventLog -logname application -after $yesterday  | select eventid,EntryType,source,message,timegenerated      
    write-output $server.name | Export-Csv “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt”

-append -noClobber
    write-output $report| Export-Csv “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt” -append -noClobber    
 }

Open in new window

0
 
LVL 1

Author Comment

by:mansoornazar
ID: 35159527
Am getting the errors :

A parameter cannot be found that matches parameter 'after'

and

A parameter cannot be found that matches parameter 'append'
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35161387
I had made some changes...try now

regards
Prashanth
$ExchServer=Get-ExchangeServer
$Date = get-date
$today = [DateTime]::Today
$today

 write-output $Date | Export-Csv “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt” -append -noClobber
foreach ($server in $ExchServer)
{
    $version = $server.admindisplayversion.Major
    $report = Get-EventLog -logname application | Where-Object {$Today -le $_.TimeWritten} | select eventid,EntryType,source,message,timegenerated      
    write-output $server.name | Export-Csv “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt” -append -noClobber
    write-output $report| Export-Csv “D:\Documents and Settings\vxmano2\Desktop\outputfile.txt” -append -noClobber    
 }

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:mansoornazar
ID: 35180261
thanks for responding....but getting the same error
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35180877
hmmm...export-csv has limitations, working on it
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 2000 total points
ID: 35361730
Hi...Sorry for the delay in response.

Try the following code....a workaround
$ExchServer=Get-ExchangeServer
$temp="C:\Documents and Settings\vxmano2\Desktop\temp.txt"
$outputfile="C:\Documents and Settings\vxmano2\Desktop\outputfile.txt"
$Date = get-date
$today = [DateTime]::Today
$today

 write-output $Date | Out-File $outputfile -Append -NoClobber
foreach ($server in $ExchServer)
{
    $version = $server.admindisplayversion.Major
    $report = Get-EventLog -logname application | Where-Object {$Today -le $_.TimeWritten} | select eventid,EntryType,source,message,timegenerated      
    $report| Export-Csv $temp
	$server.name | Out-File $outputfile -Append -NoClobber
	$readtemp=get-Content $temp
	$readtemp
	$readtemp | Out-File $outputfile -Append -NoClobber
	Remove-Item $temp	
 }

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question