• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

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
0
jskfan
Asked:
jskfan
  • 4
  • 3
2 Solutions
 
QlemoDeveloperCommented:
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
 
QlemoDeveloperCommented:
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
jskfanAuthor Commented:
how do I determine which one is my smtp server?
is it the mailbox or hub /cas server ?
0
 
QlemoDeveloperCommented:
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

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now