Solved

PowerShell SendMail

Posted on 2013-05-14
5
376 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 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39165313
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
ID: 39165333
what the function of the $ outside the bracket $($Services | Out-String)

many thanks for the quick answer
0
 
LVL 84

Assisted Solution

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

Author Comment

by:chgl
ID: 39165358
if you wont mind can you give me another example so i can understand
0
 
LVL 84

Expert Comment

by:oBdA
ID: 39165439
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 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