Solved

powershell to send an email

Posted on 2013-12-05
8
599 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 69

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 69

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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
 
LVL 69

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
To show how to generate a certificate request 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 Servers >> Certificates…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

831 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