Solved

powershell to send an email

Posted on 2013-12-05
8
590 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 20

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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Device Type 6 16
change the windows script file to BAT 10 31
SSL CERTIFIACTE, EXCHANGE 12 10
Bulk computer reset 6 12
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
This video discusses moving either the default database or any database to a new volume.

861 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

27 Experts available now in Live!

Get 1:1 Help Now