?
Solved

PowerShell SendMail

Posted on 2013-05-14
5
Medium Priority
?
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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 85

Assisted Solution

by:oBdA
oBdA earned 2000 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 85

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
New style of hardware planning for Microsoft Exchange server.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This video discusses moving either the default database or any database to a new volume.
Suggested Courses

752 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