Adding aliases to Distribution Groups using Powershell

On several occasions at work I have been asked to add email aliases to distribution groups for testing purposes. Depending on how many you have to add, in my case 30 or more, doing this through the exchange systems manager just won’t do. I mean, what self respecting systems engineer is going to copy and paste all these addresses one by one? Not me…did that the first time in a crunch and not doing it again.

Anyway, since there is a need for multiple email addresses we usually identify each by using a basic format followed by a number increment (user1, user2, user3 and so on and so forth). Since the aliases all have the same email address prefix I figured this was ripe for some powershell scripting so without further ado here is what I came up with.

#gets the distribution group name and puts it in a variable
$group = get-distributiongroup “example_group

#enter starting number here
$i = 1

#enter email prefix
$user = “user

#email domain address
$addr = “@yourdomain.com

#This is the loop. It will continue adding addresses until the ending number is reached.

do {
$newaddr = $user+$i+$addr
$group.emailaddresses += $newaddr
set-distributiongroup -Identity $group -EmailAddresses $group.emailaddresses
$i +=1
}

#enter ending number in place of “40″
while ($i -le 40)

The above example will create email aliases for the distribution group called “example_group” starting with “user1@yourdomain.com” and ending with “user40@yourdomain.com”.  If you wanted to increment another number just change the starting and ending numbers in the script.

Internal transport certificate has expired – Exchange 2007

Recently after installing systems center essentials 2007 and pushing the agent to our exchange servers I started getting an alert that the “Internal transport certificate has expired”  This certificate is crucial to the communications and transport of mail from/to the edge and hub transport servers, without it you stop recieving email. 

Thanks to SCE I was able to be somewhat pro-active and fix the issue before anyone at my company noticed any real downtime.  The alert allowed me to pinpoint the issue without having to do a lot of troubleshooting and get on with the fix. 

Unfortunately, I found the documentation on Microsoft’s technet site a little lacking.  It wasn’t that the directions were wrong just that I feel there were a few steps left out in fixing this issue properly.  In all fairness it could have been that I overlooked a step our two researching the exact order I was to perform the steps.

After finally getting the issue resolved I decided to actually document what I did, in order, so that my frustrations would not be experienced again and I could share with everyone else.

From your edge server:

 In Exchange Powershell perform the following commands:

     New-exchangecertificate

     Remove-edgesubscription

     New-edgesubscription –FileName “c:\whatever.xml”

 Copy the xml file just created to your Hub Transport server.

From your Hub Transport server:

Open Exchange Management Console and go to ”Organization Configuration > Hub Transport > Edge Subscription”

     Remove the current edge subscription

     Click New Edge Subscription (right hand task menu)

     Import the xml file you copied.

From your edge server:

     Restart Microsoft Exchange ADAM service

From your hub transport server:

Open the exchange powershell and perform the following commands:

      start-edgesynchronization

Now your exchange edge subscription should be unsubscribed/resubscribed with a newly created internal transport certificate and mail should start flowing as usual.

Blocking MAPI Client Access to your Exchange Server

Last week our exchange mailboxes were migrated to servers in a data center half way accross the United States.  We needed to leave the existing (old) Exchange 2007 cluster up in order for the mailboxes to be migrated and also to verify distribution list creation and members on the new system.  The total migration was to take approximately 48 hours and all existing Outlook clients would need to be re-configured to connect profiles to the new email system.

The morning after the migration is when the issues began.  Users opened Outlook as they normally did but with the old exchange cluster still being available and the Outlook client not yet being configured….Outlook connected to the old mail servers.  Needless to say everything looked normal to the user and they could even send and recieve mail internally but this added to the confusion.

So…to keep users (Outlook MAPI clients) from connected to the old Exchange 2007 cluster I ran accross this article on Microsoft’s tech net that allowed me to resolve my issue. 

http://support.microsoft.com/?id=288894

Adding the correct registry value for the client version was bit confusing to me but I made it work with the below values which should block everything from build 5.2653.11 up to the lastest build of Outlook 2007 with SP1 and the latest hot fixes.

Here is a synopsis of the steps I took from the above technet article along with the values I used for my registry entry.

  1. Start Registry Editor.
  2. Locate and then click the following registry subkey:
    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MSExchangeIS\ParametersSystem
  3. On the Edit menu, click Add Value, and then add the following registry value:
    Value name: Disable MAPI Clients
    Value type: REG_SZ
    Value data: 5.2653.11-12.6320.5000
  4. Exit Registry Editor.
  5. Restart the Microsoft Exchange Information Store service in the Services snap-in. Restart the Microsoft Exchange Information Store service in the Services snap-in even if you are in a cluster environment.

Entourage setup for Exchange 2007

Great article that explains the back-end and client setup for entourage and Exchange Server 2007

http://www.msexchange.org/articles_tutorials/exchange-server-2007/mobility-client-access/accessing-exchange-2007-apple-macintosh-part-1.html

Mailbox size GUI script for Exchange 2007

This is an amazingly good script that I found while searching google looking for a way to get mailbox details in a readable format using the powershell. Click on the link below to get the details.

Many thanks to the poster, Glen Scales, for sharing his extensive knowledge on the subject of Exchange development and scripting with the rest of us.

Good stuff indeed.

http://gsexdev.blogspot.com/2008/05/version-5-of-mailbox-size-gui-script.html

Using exchange 2007 powershell and Excel 2007 to send automated emails of user mailbox stats.

We are trying to get our users mailbox sizes down below 200 MB in anticipation of moving the mailboxes to a new email environment hosted by our parent company. The company I work for currently has over 1500 mailboxes with no current storage limits so the task is going to be somewhat daunting to say the least. I have been given the directive to come up with an automated way of sending each user their mailbox statistics via a personalized email on a weekly basis until the move. I decided to use the exchange powershell and Excel 2007 to accomplish this task and below are the two scripts I used to accomplish it.

First, the Exchange 2007 Powershell script:

#create the output file
#$file = new-item -itemtype file mbstats.csv -force

#create object of mailboxes
$colMailboxes = get-mailbox -resultsize unlimited

$strHeaders = “Display Name, Primary SMTP Address, Database, Department, Total Items, Mailbox Size (MB)”
write-output $strHeaders

foreach ($objMailbox in $colMailboxes) {

$mailboxStats = get-mailboxstatistics -identity $objMailbox.alias
if(!$?){
$foreach.movenext()}
else{
$strOutput = $objMailbox.DisplayName + “,” + $objMailbox.PrimarySMTPAddress + “,” + $mailboxStats.DatabaseName + “,” + $objMailbox.office + “,” + $mailboxStats.ItemCount + “,” + $mailboxStats.TotalItemSize.value.toMB()
write-output $strOutput}
}

The above script will export the mailbox stats and put them into a csv file.

Copy and Paste the above code into notepad and save the file with a ps1 extension.

Open the exchange powershell and run the script by typing the name of the ps1 file with | out-file “C:\nameofcsvfile.csv” appended to the end.

For example:

mbstats.ps1 | out-file c:\mbstats.csv

Once the csv file is created, open the csv file with excel, format the file the way you want, and save the file as an excel spreadsheet. (or..write a Macro that does this for you)

Next, the VBA code to loop the file and email people over the 200 MB limit:

Sub SendEmails()

Dim mlNewMessage As MailItem
Dim myOlApp
Dim strBody As String
Dim strFName As String
Dim strItems As String
Dim strMBSize As String

‘Loop through the spreadsheet until the end
Do Until Range(“A2″).Offset(a, 0) = “”

If (Range(“A2″).Offset(a, 4).Value >= 200) Then ‘Checks for mailbox size

strDear = Range(“A2″).Offset(a, 0).Value ‘Start Point
strItems = Range(“A2″).Offset(a, 3).Value ‘Pulls MB Items
strMBSize = Range(“A2″).Offset(a, 4).Value & ” MB” ‘Pulls MB Size

‘Builds Email Body
strBody = “You are being notified because your email storage is currently ” & strMBSize _
& ” which exceeds the new capacity of 200 MB set forth by CompanyName.” & vbCrLf & vbCrLf _
& “Your total mailbox size must be below 200 MB and it is currently above this number.” & vbCrLf & vbCrLf _
& “Please contact the technical support at YourNumber or YourEmailAddress” _
& “if you need help cleaning out or archiving your items.” & vbCrLf & vbCrLf _
& “Thank you,” & vbCrLf & vbCrLf _
& “Your Name” & vbCrLf _ ‘Signature
& “Your Number” & vbCrLf _ ‘Signature
& “Your Email Address” ‘ Signature

strDear = Left(strDear, InStr(1, strDear, ” “, vbTextCompare)) ‘Pulls First Name from Full Name

Set myOlApp = CreateObject(“Outlook.Application”) ‘Create New Outlook Item
Set mlNewMessage = myOlApp.CreateItem(olMailItem) ‘Create New Mail Item

‘Defines Email Body
mlNewMessage.Body = strDear & “,” & vbCrLf & vbCrLf _
& strBody

mlNewMessage.Subject = “Harry Norman mailbox over the size limit” ‘Defines Subject
mlNewMessage.To = Range(“A2″).Offset(a, 1) ‘Defines To

mlNewMessage.Send ‘Sends Email Message

Set myOlApp = Nothing ‘Clears mlOlApp Variable
Set mlNewMessage = Nothing ‘Clears mlOlApp Variable

a = a + 1 ‘Moves to Next Record

Else
a = a + 1 ‘Next Record
End If

Loop

End Sub

Auto-response to external (Internet) addresses with Exchange 2007 and Outlook 2007

Recently I was asked to setup an email address that would be used for resume subittals for a position my company is hiring for.  I was informed that when emails were recieved by this account an auto-response would need to be generated that attached a questionnaire (part of the weeding out process) as part of the automatically generated reply.  After thinking about the best way to accomplish this here is what I came up with.

I set up a mail enabled public folder called “IT Jobs” giving the folder the appropriate email address.  Next, using the public folder “Folder Assistant” I created a rule to be applied to all messages that were received or posted to this folder.  The “Folder Assistant” can be found by right-clicking the public folder you just created > going to “Properties” > then clicking on the “Administration” tab.

Once you are there , just click the “Folder Assistant” button to get started creating your rule. I created my rule by checking the “Reply with” box under the “perform these actions” section of the folder assistant.  Next, in order to create my auto-response template I chose the “Template” button next to the “Reply with” checkbox to bring up a blank email message.  You do not need to put anything in the TO:, BCC:, or other fields unless you want to.  After you are done typing out the email and attaching any documents you can save the message template and click OK to close the windows.  You are now ready to test your auto-response.

One important thing that I discovered while doing this is that none of the auto-responses were working to external addresses.  In order to fix this you must go into the Exchange Management Console > Organization Configuration > Hub Transport > Remote Domains > open Default and go to “Format of original message sent as attachment to journal report:” and make sure the “Allow Automatic Replies” is enabled.  This will allow the auto-response messages to reach the external senders.