Solved

Script to export event logs in csv - entire exchnage environment

Posted on 2011-03-16
6
829 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
In this video we show how to create a Distribution Group 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 >>…
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 …

759 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

22 Experts available now in Live!

Get 1:1 Help Now