Solved

PowerShell SendMail

Posted on 2013-05-14
5
364 Views
Last Modified: 2013-05-15
hi Guys,

I have written this powershell command however the services status does not appear on the body of the email, instead it sends me a blank message:

$services=Get-Service -ComputerName sss-vfinsvr01, sss-vshrepnt, sss-fnp01 *econnect*, Spa*, Tomcat* | select name, Displayname, machinename, status | sort machinename


Send-MailMessage -To xxxxn@xxeh.org -from xxxxn@xxeh.org -Subject "Services Status" -Body "$services" -SmtpServer sss-exch01

thanks in advance,
k
0
Comment
Question by:chgl
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
Use
Send-MailMessage -To xxxxn@xxeh.org -from xxxxn@xxeh.org -Subject "Services Status" -Body "$($Services | Out-String)" -SmtpServer sss-exch01

Open in new window

0
 

Author Comment

by:chgl
Comment Utility
what the function of the $ outside the bracket $($Services | Out-String)

many thanks for the quick answer
0
 
LVL 82

Assisted Solution

by:oBdA
oBdA earned 500 total points
Comment Utility
The "$()" tells Powershell to first evaluate the expression inside the brackets.
0
 

Author Comment

by:chgl
Comment Utility
if you wont mind can you give me another example so i can understand
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Another example where you need this kind of subexpression is when you're trying to write an object's property:
$Spooler = Get-Service "Spooler"
Write-Host "Spooler status: $($Spooler.Status)"

Open in new window

"get-help about_operators" is not very helpful, this here is better:
Powershell Operators
http://ss64.com/ps/syntax-operators.html
This one's a bit more in-depth:
Effective PowerShell Item 10: Understanding PowerShell Parsing Modes
http://rkeithhill.wordpress.com/2007/11/24/effective-powershell-item-10-understanding-powershell-parsing-modes/
0

Featured Post

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
The viewer will learn how to count occurrences of each item in an array.

744 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