Create Exchange 2007 script
I would like to create a report which i could run weekly/monthly of the amount of emails that are sent/received from all users from some date to the current data. Is this possible and if so how and where do i start? Im guessing this may have to do with cmdlets but not 100% sure. Any examples would be great.Thank you in advance.
June 12th, 2009 6:42pm
This would be easier with either Log Parser orProcess Tracking Log tool.Here are some references to get information from message tracking logs with those tools...
References:
Advanced Exchange 2007 Transport Logs Troubleshooting using Log Parser - Part 1
http://msexchangeteam.com/archive/2007/11/12/447515.aspx
Advanced Exchange 2007 Transport Logs Troubleshooting using Log Parser - Part 2
http://msexchangeteam.com/archive/2007/11/28/447598.aspx
Process Tracking Log tool for Exchange Server 2007
http://msexchangeteam.com/archive/2008/02/07/448082.aspx
Amit Tank | MVP Exchange Server | MCITP: EMA | MCSA: M | http://ExchangeShare.WordPress.com
Free Windows Admin Tool Kit Click here and download it now
June 12th, 2009 7:29pm
And, once you have log parser, look here for information on using log paser from within powershell :)http://muegge.com/blog/?p=62http://muegge.com/blog/?p=65Google will bring up more examples.Karl
June 12th, 2009 7:37pm
More resources:
Count number of daily emails on Exchange 2007Exchange Messaging Statistics
Free Windows Admin Tool Kit Click here and download it now
June 15th, 2009 5:22am
i wrote the following to update a sql database with statistics from our hub transport servers:
function New-SQLconnection
{ Param ([string]$server,[string]$database,[string]$connectionName = $scriptName)
if (test-path variable:\conn)
{ $conn.close() }
else
{ $conn = new-object ('System.Data.SqlClient.SqlConnection') }
$connString = "Server=$server;Integrated Security=SSPI;Database=$database;Application Name=$connectionName"
$conn.ConnectionString = $connString
$conn.StatisticsEnabled = $true
$conn.Open()
$conn
}
function NonQuery-SQL
{ Param ($query, $conn, $CommandTimeout = 30)
$sqlCmd = New-Object System.Data.SqlClient.SqlCommand
$sqlCmd.CommandTimeout = $CommandTimeout
$sqlCmd.CommandText = $query
$sqlCmd.Connection = $conn
$RowsAffected = $sqlCmd.ExecuteNonQuery()
if ($? -eq $false)
{ $RowsAffected = -2 }
$RowsAffected
}
function Remove-SQLconnection
{ Param ($connection)
$connection.close()
$connection = $null
}
##Connect to the SQL database
$scriptName = $myInvocation.MyCommand.Name
$server = "SQLSERVER\INSTANCE"
$database = "DatbaseName"
$myConn = New-SQLconnection $server $database
if($x.state -eq "closed")
{ "Failed to establish a connection";EXIT }
##Get the start and end date
$end = Get-Date
$start = $end.AddDays(-1)
$end = $end.ToShortDateString()
$start = $start.ToShortDateString()
##Get the total size of messages
$size = $null
$servers = Get-TransportServer
foreach($server in $servers)
{ $messages = Get-MessageTrackingLog -Server $server -Start $start -End $end -EventId "Deliver" -ResultSize unlimited
foreach($m in $messages)
{ $size += $m.TotalBytes }
$count = $messages.count
$size = $size/1024/1024/1024
$query = "INSERT INTO Totals (Timestamp,HubTransportServer,TotalMessageCount,TotalMessageSize) values ('" + $start + "','" + $server + "','" + $count + "','" + $size + "')"
$data = NonQuery-SQL $query $myConn
if($data -eq -2)
{ Write-Host "Creation of new record failed for MailTo" }
}
## Close the SQL connection
Remove-SQLconnection $myConn
June 15th, 2009 11:12pm