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
Solved

Script to export event logs in csv - entire exchnage environment

Posted on 2011-03-16
6
841 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

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.

Question has a verified solution.

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

Read this checklist to learn more about the 15 things you should never include in an email signature.
In-place Upgrading Dirsync to Azure AD Connect
In this video we show how to create a Contact 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 >> Contact ta…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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