Confuseis
Confuseis

Reputation: 13

Output in Email Body Formatting Warped

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?

Thanks

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 exchange 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" 

Upvotes: 0

Views: 1544

Answers (1)

Matthias Kuhs
Matthias Kuhs

Reputation: 1

Until we see how exactly your email looks like we can only guess.

But I assume that you mean that all the lines from the text file that your are putting as the body of the email are together in one long line and they are not displayed as individual lines any more in the email. I had a similar issue in the past and solved it with this:

$body= ( (Get-Content mailboxsize.txt) -join "`n")

(you might not need the outermost parantheses).

Upvotes: -1

Related Questions