Solved

powershell to send an email

Posted on 2013-12-05
8
604 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 70

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 70

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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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 70

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

Independent Software Vendors: 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!

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

717 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