Powershell to send email with delivery notification enabled

Powershell to send email with delivery notification enabled. Once mail is delivered to the recipient mailbox and delivery notification mail will be sent to the sender mailbox. Below powershell help you to atchive the same

$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.Headers.Add(“Disposition-Notification-To”, “from@domainname.com”)
$msg.DeliveryNotificationOptions = “OnSuccess”
$msg.From = “from@domainname.com”
$msg.To.Add(”to@domainname.com”)
$msg.Subject = “Make the Delivery Recipt Work Please”
$msg.Body = “In a perfect world this email will generate a delivery receipt”
$msg.Attachments.Add($att)
$smtp.Send($msg)

Powershell to Settup ManagedFolderAssistantSchedule in all Exchange 2007 Mailbox Servers

The managed folder assistant is a Microsoft Exchange Mailbox Assistant that creates managed folders in users’ mailboxes and applies managed content settings to them. When the managed folder assistant is running, it processes all of the mailboxes on a server. If the managed folder assistant does not finish processing the mailboxes on the server during the time that you have scheduled, it automatically resumes processing where it left off the next time it runs. There is one managed folder assistant for each server

Get-ExchangeServer | Where { $_.AdminDisplayVersion.ToString().SubString(0, 10) -eq “Version 8.” `

-and $_.ServerRole -eq “Mailbox” } |

ForEach { Set-MailboxServer -Identity $_.Identity `

-ManagedFolderAssistantSchedule “Sun.1:00 AM-Sun.3:00 AM”, `

“Mon.1:00 AM-Mon.3:00 AM”, “Tue.1:00 AM-Tue.3:00 AM”, `

“Wed.1:00 AM-Wed.3:00 AM”, “Thu.1:00 AM-Thu.3:00 AM”, `

“Fri.1:00 AM-Fri.3:00 AM”, “Sat.1:00 AM-Sat.3:00 AM” }

http://technet.microsoft.com/en-us/library/bb123958.aspx

LogParsing with Exchange SMTP Protocol Logs

SMTP Protocol logs are not enabled by default.  In Both Exchange 2003 and Exchange 2007 SMTP Protocol logs need to be manually enabled.

In Exchange 2003 SMTP protocol logging is enabled on the SMTP Virtual Servers

Please download log parser from following link

http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en

Below log parser command help you to get list of servers connecting to Exchange 2003 server through SMTP

logparser “Select cs-username,count (*) as Hits from N:\ex0910.log GROUP BY cs-username ORDER BY Hits Desc” -o:DATAGRID

Below is the output it provides the list of server name and number of hits from that specific servers

Below mentioned article describes on how to enabled smtp protocol logging on Exchange 2007 and log files path

/2009/10/

Below command helps you to get the list of servers connect to the exchange server for sending emails

logparser “select REVERSEDNS(EXTRACT_PREFIX(remote-endpoint,0,’:’)) as RemoteSendingHost, count(*) as Hits from RECV*.log group by RemoteSending Host order by Hits DESC” -i:CSV -nSkipLines:4  -o:DATAGRID

related articles

http://msexchangeteam.com/archive/2007/09/12/446982.aspx
http://msexchangeteam.com/archive/2007/11/12/447515.aspx
http://msexchangeteam.com/archive/2007/11/28/447598.aspx
http://linuxlore.blogspot.com/2006/11/howto-use-microsofts-logparser-to.html

SMTP Protocol Logging In Exchange 2007

Exchange Protocol Logging is not Enabled by Default in Exchange 2007. We have to enable the logging if required. Below powershell commands help you to enable the

Set-SendConnector “Send Connector Name” -ProtocolLoggingLevel verbose
Set-ReceiveConnector “Connector Name” -ProtocolLoggingLevel verbose

You can also enable the connector through Exchange Management Console.

EMC -> Exchange Orginization -> Hub Transport Servers -> Send connectors (tab) -> Right click on the required connector properties -> select Verbose

Location of STMP Logs in the below mentioned location
\Exchange Server\TransportRoles\Logs\ProtocolLog\SmtpReceive
\Exchange Server\TransportRoles\Logs\ProtocolLog\SmtpSend

Powershell Script to check Health Services running in all Exchange 2007 servers

Below power shell Command Gets Each of the Exchange 2007 Server in the Environment and Check the Health Services then display the status.  Exchange Services varies depend on the type of services installed. Mailbox Services , Hubtransport Servers, Client Access server has some common service and some unique services. Test-Serverhealth performs the health check only on required services depending on the type of server Installed.

$ExchServer=Get-ExchangeServer
foreach ($Server in $ExchServer)
{
echo $Server.name (Test-ServiceHealth $Server)
}

Restricting Exchange 2007 users to force outlook Cached mode

Outlook clients are used to connect to the Exchange 2007 to access email. Non – Cached Mode clients can generate a significant amount of disk I/O traffic and affect the performance of the server. Forcing all clients to use Cached Mode can Improve the  performance

Below powershell forces to apply the same for all the users

Get-Mailbox | Set-CASMailbox -MAPIBlockOutlookNonCachedMode $true

Below power shell helps to apply for the Individual users

Get-mail username | Set-CASMailbox -MAPIBlockOutlookNonCachedMode $true

Powershell to Export Exchange backup Status to Email in HTML format

$wid  = “1200”
$bord = “2”
$colour =”BLUE”
$Fcolour = “White”

“<table width=$wid border=$bord>” | out-file -filePath “C:\Powershell\BackupDetails.txt” -append
“<tr> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font color=$Fcolour> <b>Server</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font color=$Fcolour> <b>StorageGroupName</b> </td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font color=$Fcolour><b>LastFullBackup</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font color=$Fcolour><b>LastIncrementalBackup</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font color=$Fcolour><b>BackupInProgess</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“</tr> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append

Get-MailboxDatabase | where {$_.Recovery -eq $False } | Select-Object -Property Server, StorageGroupName, Name , LastFullBackup, LastIncrementalBackup, BackupInProgess | Export-csv Backuptatus.csv

foreach($line in $csv)
{
$MailboxStats =  Get-MailboxStatistics  $Line.Alias | Select TotalItemSize,Itemcount,LastLogoffTime,LastLogonTime
$L = “{0:N0}” -f $mailboxstats.totalitemsize.value.toMB()
$Size = “”
$Len = $L.Split(‘,’)
for ($i=0; $i -lt $Len.length; $i++)
{
$Size = $Size +$Len[$i]
}
$temp=$Line.PrimarysmtpAddress
$adobjroot = [adsi]”
$objdisabsearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
$objdisabsearcher.filter = “(&(objectCategory=Person)(objectClass=user)(mail= $Temp)(userAccountControl:1.2.840.113556.1.4.803:=2))”
$resultdisabaccn = $objdisabsearcher.findone() | select path

“<tr> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font size=2 color=$Fcolour> <b> $Line.Server </b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font size=2 color=$Fcolour><b>$Line.StorageGroupName</b> </td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font size=2 color=$Fcolour><b>$Line.Name</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font size=2 color=$Fcolour><b>$line.LastFullBackup</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font size=2 color=$Fcolour><b>$Line.LastIncrementalBackup</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“<td BGCOLOR=$colour><font size=2 color=$Fcolour><b>$Line.BackupInProgess</b></td> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
“</tr> ” | out-file -filePath “C:\Powershell\BackupDetails.txt”  -append
}

$smtpServer = “hutserver”
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “FromAddress”
$msg.To.Add(”ToAddress”)
$sub = Date
$msg.Subject = “Exchange Database Backup Status Report  ” + $sub

$msg.IsBodyHTML = $true

$UserList = Get-Content “C:\Powershell\BackupDetails.txt”

$body = “”

foreach($user in $UserList)
{
$body = $body + $user + “`n”

}

$msg.Body = $body

$smtp.Send($msg)
Exit

Please find the copy of the in the below link

http://powershell.com/cs/members/smtpport25.wordpress/files/BackupStatus.ps1.aspx

Powershell to Get Exchange mailbox Database and Public Backup Status Report

Below power shell help you to get backup status of all the Exchange Database in Exchange 2007 Servers

Get-MailboxDatabase `
| where {$_.Recovery -eq $False } `
| Select-Object -Property Server, StorageGroupName, Name , LastFullBackup, LastIncrementalBackup, BackupInProgess `
| Sort-Object -Property Server, StorageGroupName, Name `
| Format-Table -AutoSize

Get-PublicFolderDatabase `
| Select-Object -Property Server, Storagegroupname, Name , LastFullBackup, LastIncrementalBackup, BackupInProgess `
| Sort-Object -Property Server, StorageGroupName, Name `
| Format-Table -AutoSize