Solved

PowerShell SendMail

Posted on 2013-05-14
5
366 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 83

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 83

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 83

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
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.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

911 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

20 Experts available now in Live!

Get 1:1 Help Now