Solved

PowerShell - TextOnly Email (fix column output)

Posted on 2014-09-15
2
520 Views
Last Modified: 2014-09-16
Experts,

I have a working script that can successfully send email to users, informing them of their excessive mailbox size and requesting them to assist in cleaning it up to make space on the back-end.  Prior to going into production with this thing, I'd like to clean up the output a little.

The script works, however, the column spacing gets misaligned within outlook (Outlook & MS Office spaces take less real estate than other characters).  Even pasting in Experts-Exchange will give me the same "ugly" output.

For Example:

Name                          FolderPath                    FolderSize                                    ItemsInFolder
----                          ----------                    ----------                                    -------------
Calendar                      /Calendar                     5555963605B                                           11828
Inbox                         /Inbox                        1290037840B                                           23475
Deleted Items                 /Deleted Items                236406455B                                              515
Sent Items                    /Sent Items                   227181035B                                             6298
Inbox                         /Sent Items/Change Control... 58623161B                                              3680
Conflicts                     /Sync Issues/Conflicts        49249238B                                               553
Inbox                         /Inbox/BTT Extracts/Inbox     47278216B                                              3503
Inbox                         /Sent Items/Change Control... 47219534B                                              3502
Drafts                        /Drafts                       39207751B                                               177

Copying and pasting this into "notepad" lines the columns up perfectly.  Would somebody know if it's possible to keep this text-only, but make the spacing a bit more readable?

Here's a copy of the scrubbed PS script.

// PowerShell script =========================================================================

$strMailboxServer = "ScrubbedOutput.none.Com"
$intSizeLimit = "7Gb"
$objSMTPFrom = New-Object System.Net.Mail.MailAddress("DoNotReply@none.com", "Exchange System Administration")
$strSMTPMessageSubject = "Action required - Your mailbox is in excess of $intSizeLimit"
$strSMTPMessageBody = "$strDisplayName, $strDynamicContent"
$vbCrLf = [Char]13 + [Char]10
$strSMTPRelayDNS = "relay.none.com"
$PSEmailServer = $strMailboxServer

$arrMailboxInfo = Get-MailboxServer $strMailboxServer |
      Get-MailboxStatistics |
      Where-Object {$_.TotalItemSize -ge $intSizeLimit}

ForEach ($objMailbox in $arrMailboxInfo) {
      $strID = $objMailbox.Identity
      $strDisplayName = $objMailbox.DisplayName
      $strPrimarySMTP = Get-Mailbox $strID | Select PrimarySmtpAddress
      $strMailboxSizeDistribution = Get-MailboxFolderStatistics $strID |
            Where-Object {$_.FolderSize -ge 25Mb} |
            Sort FolderSize -Descending |
            Select -First 10 |
            FT Name,FolderPath,@{Name="Size (Mb)";Expression={[math]::Round($_.FolderSize.ToBytes()/1MB)}},@{Expression={$_.ItemsInFolder};Label="# of Items"} -Auto | Out-String
      $strMailboxSizeDistribution = [String]::Join([Environment]::NewLine, $strMailboxSizeDistribution)
      $objSMTPTo = New-Object System.Net.Mail.MailAddress("$strPrimarySMTP", "$strDisplayName")
      $objSMTPMessage = New-Object System.Net.Mail.MailMessage ($objSMTPFrom, $objSMTPTo)
      $objSMTPMessage.Subject = "Action required - Your mailbox is in excess of $intSizeLimit"
      $objSMTPMessage.Body = `
            $strDisplayName + "," + $vbCrLf + $vbCrLf + `
            "The size of your mailbox has grown very large, and is in excess of $intSizeLimit.  Please take corrective action and remove any items that are no longer required." + $vbCrLf + $vbCrLf + `
            "The following folders are listed in order to assist in the process of identifying where items can be removed:" + $vbCrLf + `
            $strMailboxSizeDistribution + $vbCrLf + `
            "*Keep in mind that items retained in your Deleted Items folder continue to take space.  If these are not needed, please delete them." + $vbCrLf + `
            "Your cooperation is greatly appreciated.  If you require further assistance, please contact your local help desk."
      $objSMTPMessage.IsBodyHtml = $False
      $objMailer = New-Object System.Net.Mail.SmtpClient($strSMTPRelayDNS)
      $objMailer.Send($objSMTPMessage)
      }

// ========================================================================================
0
Comment
Question by:usslindstrom
2 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 40323465
The issue here is the use of fixed-width vs. non-fixed-width fonts.  If you're sending in plain text the only fix is to have the client machine's email client used a fixed-width font for displaying plain text emails.  Your only other option is to send the email as HTML where you can specify what font to use or create tables so that text is aligned by the cells.
0
 
LVL 5

Author Closing Comment

by:usslindstrom
ID: 40325428
Much appreciated on the assistance.  You're absolutely right.

Based on your two suggested options, I actually opted to go yet another route - and export results to a text file, then attach the file to the outbound E-mail.  Much appreciated.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
install .NET 3.5 on windows 10 13 45
exchange, outlook 8 57
Simple Q for someone 3 17
Exchange 2007 Powershell Query 9 5
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now