I'm using this cmdlet to try to send an email which the body of email is contains the powershell output. PS C:\ps> Send-MailMessage -From postmaster@contoso.com -To suriya@sapura.contoso.com -Subject "SCR Test Result" -Body "SCR result + `n + $sr.summarycopystatus" -Smtpserver send.contoso.com The email was able to sent to my mailbox but the contents look like below: 2/8/2007 3:32 PM SERVER! Disk Space Report Disk Drive Size(GB) Free(GB) ---------- -------- -------- C:\ 8.01 2.98 E:\ 60.36 54.7 F:\ 150 143.41 SERVER2 Disk Space Report Disk Drive Size(GB) Free(GB) ---------- -------- -------- C:\ 7.96 4.61 E:\ 60.35 31.14 F:\ 68.35 48.03 SERVER3 Disk Space Report Disk Drive Size(GB) Free(GB) ---------- -------- -------- C:\ 7.81 4.61 E:\ 60.51 46.44 F:\ 136.7 111.81 G:\ 136.7 128.64 H:\ 136.7 66.13 I:\ 136.7 Please help to array in more readable format
Try using:
$output = you command | out-string
Send-MailMessage -body $output
Hi, it appears that $sr.summarycopystatus is in raw format which results in the contents being shown as above.
You can format the summarycopystatus as shown below and adding the formatted text to the body:
$a = [string]$sr.summarycopystatus
$a = $a.replace("SERVER","`nSERVER")
$a = $a.replace("C:","`nC:")
These will insert new line at SERVER and C: text.
After that
Send-MailMessage .... ...... -body $a .....
The email is:
Name SummaryCopyStatus CopyQueueLength ReplayQueueLength LastInspectedLogTime ---- ----------------- --------------- ----------------- -------------------- SG1 Healthy 0 1601 27/4/2011 4:14:46 PM Second Storage Group NotConfigured 0 0 SG2 Healthy 0 1290 27/4/2011 4:13:40 PM SG3 Healthy 0 1284 27/4/2011 4:14:41 PM SG4 Healthy 0 1995 27/4/2011 4:14:14 PM SG5 Healthy 0 2392 27/4/2011 4:14:45 PM SG6 Healthy 0 50 27/4/2011 4:14:41 PM SG7 Healthy 0 3907 27/4/2011 4:14:42 PM SG8 Healthy 0 3936 27/4/2011 4:14:48 PM
It seem that the output was not arrange in correct array.
The output seems to be different from what you have posted earlier.
Could you provide what details will the command output?
You can preview the output in powershell or powershell ISE to check
if the rows are correct. If not, you can format the string or array before
attaching to the mail body.
$scr = Get-StorageGroupCopyStatus -Server Exch01 | out-string
$FromAddress = "postmaster@contoso.com"
$ToAddress = "Administrator@contoso.com"
$MessageSubject = "Server Copy Status"
$SendingServer = "send.contoso.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject,$scr
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
Tested and the alignment is correct. (Didnt use send-mailmessage as 2007 do not have that command.)
- Marked as answer by Alan ZhuModerator Monday, May 02, 2011 1:48 AM
This is result via webmail is working but my outlook still the same. I not sure it is because of my laptop resolution since on my colleagies laptop appeared to get good result
Thank you so much.
It's completely working!