Solved

Script to export event logs in csv - entire exchnage environment

Posted on 2011-03-16
6
834 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 500 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

Being driven mad by email signature updates?

Having to make a change to your users’ email signatures, yet again? Feel like your head is going to explode? Rely on an Exclaimer email signature management solution to make the process simple!

Question has a verified solution.

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

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this video we show how to create a User Mailbox 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 Recipients >> Mailb…
In this video we show how to create an email address policy 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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now