Solved

PowerShell SendMail

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SYSVOL folder permission security best practice ? 14 52
exchange 13 25
Mail not being received 19 28
Exchange 2016 Size restrictions. 13 48
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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 …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

730 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