Solved

powershell to send an email

Posted on 2013-12-05
8
601 Views
Last Modified: 2013-12-05
I have this powershell command that displays the free disk space on all drives in the remote computer.
 gwmi win32_volume -computername remotecomputername -Filter 'drivetype = 3' | select driveletter, label, @{LABEL='GBfreespace';EXPRESSION={$_.free
space/1GB} }

I need to add something to the script so that it will send an email for the output of the powershell command

then I will schedule it in my task scheduler.

Thanks
0
Comment
Question by:jskfan
[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
  • 4
  • 3
8 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 450 total points
ID: 39699768
Firstly, I would cut the free GBs to an integer number, or used fixed precision.
Sending an email is very easy:
gwmi win32_volume -computername localhost -Filter 'drivetype = 3' |
  select driveletter, label, @{n='GBfreespace';e={[int]($_.freespace/1GB)} } |
  ft -auto |
  Send-MailMessage -From Me@Here.Com -To You@There.com -Subject 'Daily Freespace Report' `
    -SmtpServer mail.here.com

Open in new window

Variants are to send the mail body as HTML table.
0
 
LVL 20

Assisted Solution

by:n2fc
n2fc earned 50 total points
ID: 39699771
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39699841
And why should you want to use an external script if there is a ready-to-use, simple cmdlet doing the same (and even more)?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jskfan
ID: 39699863
how do I determine which one is my smtp server?
is it the mailbox or hub /cas server ?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39699870
Whatever server runs the SMTP receiver - usually the hub. You can use your public mail address, that should work at all times.
0
 

Author Comment

by:jskfan
ID: 39699880
I tried it, but it does not send email....it does not throw error, but does not send email
0
 

Author Comment

by:jskfan
ID: 39699882
it worked now...Thanks
0
 

Author Closing Comment

by:jskfan
ID: 39699883
Thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…
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…

756 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