Tag Archives: PowerShell

How to Export Results from Exchange Management Shell Without Truncating Data

Recently I was using the Exchange Management Shell to generate a .csv file from the Message Tracking Logs. Unfortunately, the output in the .csv file was truncated as the command shell has a default width of 120 characters. This led to truncated data, which wasn’t going to do me any good. So I used two PowerShell cmdlets to format the results into an Excel-friendly format without truncating the data, Format-Table and Out-String.

You can read more about both of these cmdlets below of them using the links below:



As an example, I’ll use the get-MessageTrackingLog command to export a list of Delivery Status Notifications to a .csv file.

get-MessageTrackingLog -Server "MailboxServer01" -EventID "DSN" -Start "9/24/2011 5:00:00 AM" -End "9/24/2011 6:00:00 AM" -ResultSize Unlimited | Format-Table -AutoSize | Out-String -Width 20000 > c:\DSN_09242011.csv

Adding those two cmdlets generated the expected results, which I was able to easily import and manipulate in Excel.

Mail Enable All Existing Distribution Groups within an OU

Using the EMC to mail enable a distribution group is incredibly inefficient as you can only perform the action on one group at a time.  The EMS isn’t much better as there is not a native command to target every group within a specific OU.

Why would you need to mail enable a distribution group?  Well, remember with Exchange 2007/2010, you could create a new group in Active Directory Users & Computers, and even make it a Universal Distribution Group, but Exchange won’t see it until you mail enable it.  In my case, I had to import a LARGE number of groups from a recent aquisition, so I had them in AD but did not have them mail enabled yet.

In order to do this, we need to create a new PowerShell script with the following code:

Get-Group -OrganizationalUnit "OU=users,DC=domain,DC=com" | ?{ $_.GroupType  -Match "Universal" } | %{ 

# Check to see if the group is mail enabled or not.   

   If ($_.RecipientType -eq "Group") {
      Enable-DistributionGroup $_.DistinguishedName

Just change the “OU=users,DC=domain,DC=com” to whichever OU you are targeting and you should be good to go.