Link to home
Start Free TrialLog in
Avatar of mansoornazar
mansoornazarFlag for Afghanistan

asked on

Script to export event logs in csv - entire exchnage environment

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    
 }
======================

Avatar of prashanthd
prashanthd
Flag of India image

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

Avatar of mansoornazar

ASKER

Am getting the errors :

A parameter cannot be found that matches parameter 'after'

and

A parameter cannot be found that matches parameter 'append'
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

thanks for responding....but getting the same error
hmmm...export-csv has limitations, working on it
ASKER CERTIFIED SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial