Solved

powershell to send an email

Posted on 2013-12-05
8
589 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
  • 4
  • 3
8 Comments
 
LVL 68

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 19

Assisted Solution

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

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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 68

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you don't know how to downgrade, my instructions below should be helpful.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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 Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

762 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

16 Experts available now in Live!

Get 1:1 Help Now