Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

SMPTdiag Powershell Script

*** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ***

This script will take input of the Sender Email address as well as the Receiver Email address. Once it checks for an Email address smtpdiag.exe /v (verbose logging) is executed and written to c:\userprofile\desktop\smtpdiag\smtpdiag.log

Tested on Windows Server 2k8 R2 and Exchange 2010

Usage:
1: You must download SMTPdiag from the Microsoft Website here (http://www.microsoft.com/en-us/download/details.aspx?id=11393).
2. Copy the smtpdiag.exe and this script to a folder on you computer. (I put is all in c:\smtpdiag)
3. Open Powershell and navigate to the folder in step 2.
4. Run the script by typing .\smtpdiag.ps1

# **** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ****
#
# Tested on Windows Server 2k8 R2 and Exchange 2010
#
# Usage:
#
# 1: You must download SMTPdiag from the Microsoft Website
# here (http://www.microsoft.com/en-us/download/details.aspx?id=11393).
#
# 2. Copy the smtpdiag.exe and this script to a folder on you computer.
# (I put is all in c:\smtpdiag)
#
# 3. Open Powershell and navigate to the folder in step 2.
#
# 4. Run the script by typing .\smtpdiag.ps1
#
# The logfile created by the script is created at userprofile\smtpdiag\smtpdiag.log


# Send from email address
$senderEmail = Read-Host "Senders Email address"
# Kill the script if nothing entered
if ($senderEmail.Length -eq 0){
    Write-Host -ForegroundColor Red "Invalid Sender Email Address"
    Exit
    }

# Send to email address
$receiverEmail = Read-Host "Receiver Email address"
# Kill the script if nothing entered
if ($receiverEmail.Length -eq 0){
    Write-Host -ForegroundColor Red "Invalid Receiver Email Address"
    Exit
    }

# Log file location (Defaults to the desktop of the userprofile\smtpdiag\smtpdiag.log)
$logPath = "$env:userprofile\desktop\SMTPdiag"
$logName = "smtpdiag.log"
$logFile = "$logPath\$logName"

# Check if logPath exists
if (!(Test-Path $logPath)) {
# create it silently
[void](new-item $logPath -itemType directory)
}

c:\smtpdiag\smtpdiag.exe $senderEmail $receiverEmail /v |
Out-File $logFile -Append

Write-Host ""
Write-Host -ForegroundColor cyan "Script Complete, Logfile location $logFile"

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.