Exchange 2007 console tips and tricks
Exchange Server 2007 introduced a new GUI management console (Exchange Management Console) to replace the Exchange System Manager (ESM) of previous versions. This earlier blog post The new Exchange 2007 Management Console overview gives an overview of the console. In this blog post I’ll show some tips and tricks of the console.
Validate an email address
Validating an e-mail address could be really usefull. Here is a really good thing to do before sending that address to a creation/modification script :
Function ValidMail ([string]$Mail ) {
$regexp=”^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}” +
“.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+” +
“.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$”if ($Mail -match $regexp) {
$return=$True
}
Else {
$return=$False
}
Return $return
}
Sending mail using Powershell
Sending an email in powershell can be done, once more, using .Net Frameword 🙂
Function SendMail([string]$file,[string]$sender,[string]$recipients,[string]$server){
$message = new-object System.Net.Mail.MailMessage
$message.from = $sender
$message.subject = “My first mail in Powershell”
$message.body = “Hello,” + “`r`n” +”This mail was sent automatically by the script” + “`r`n” +”You will find in attachement all information you asked.” + “`r`n” +”Regards”
foreach ($rec in $recipients){$message.TO.add($rec)}