No announcement yet.

Output in email body formatting warped

  • Filter
  • Time
  • Show
Clear All
new posts

  • Output in email body formatting warped

    Hi All
    I am completly new to powershell & am googling about for code.
    I have been able to so far to send the results of a powershell query by email and am mightly impressed it worked.

    When the query is done on the command line it works great, by email the output is spread wide and the fields dont align with each other.
    I have pasted my commands below. I am querying the Exchange Mailbox sizes and wish to sort by the biggest down. This works great and I out put it to a text file.

    I then read the text file and substitute it for the body of the email.
    On the outlook email recepient end It looks to me like the window size of outlook causes the text to wrap around and it is no longer displayed lengthways.

    Is there anything I can do?


    Below gets data

    Get-WMIObject -Class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName MyExchangeServer | Where-Object {$_.LastWriteTime -le (Get-Date).AddYears(1)} | Select-Object MailboxDisplayName,Size | sort-object size -descending

    Below tells which exchnage server to use

    $psEmailServer = "MyExchangeServer"

    Below is the text file containing the data I need assigned to $body

    $body= (Get-Content mailboxsize.txt)

    Below sends the email using the contents of the email as the email body, BUT it dosent come out right and its out of alignment in outlook.

    send-mailmessage -from "[email protected]" -to "[email protected]" -subject "test powershell email" -body "$body"
    Last edited by confuseis; 18th January 2014, 19:46.