[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • 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
 
QlemoC++ DeveloperCommented:
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
 
QlemoC++ DeveloperCommented:
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
 
QlemoC++ DeveloperCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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