powershell to send an email

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
jskfanAsked:
Who is Participating?
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
jskfanAuthor Commented:
how do I determine which one is my smtp server?
is it the mailbox or hub /cas server ?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Whatever server runs the SMTP receiver - usually the hub. You can use your public mail address, that should work at all times.
0
 
jskfanAuthor Commented:
I tried it, but it does not send email....it does not throw error, but does not send email
0
 
jskfanAuthor Commented:
it worked now...Thanks
0
 
jskfanAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.