Geeks With Blogs



Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.


Lance's TextBox » About Me » My Resume »Twitter

I put the following function in my PowerShell profile so that I can just bring up my PowerShell console and type myself a quick “todo” note that automatically gets emailed to me for later.  There are several things of note in this tiny script:

1.  Note the use of the $args variable to effectively allow the user to enter $msg parameter without quotes even if it contains whitespace.

2.  In this particular example I’m sending the email through Gmail., port 587, SSL and authentication required.

3.  Check outhe $gmailcred variable, which gets set earlier in my profile.  It gets read from a secure string file.


function todo {
  param([string] $target = "work",
        [string] $msg )
  switch ($target)
  "work" { $target = "" }
  "home" { $target = "" }
  $emailFrom = ""
  if ($args -ne "") {
    $msg = $msg + " " + $args
  $subject = "Todo: " + $msg
  $body = $msg
  $smtpServer = ""  
  $smtp = new-object Net.Mail.SmtpClient($smtpServer, 587)
  $smtp.EnableSsl = $true
  $smtp.Credentials = [Net.NetworkCredential]($gmailcred)
  $smtp.Send($emailFrom, $target, $subject, $body)

Technorati Tags: ,,
Posted on Tuesday, October 26, 2010 1:27 PM PowerShell | Back to top

Comments on this post: Quick PowerShell “Todo” Gmail Emailer

# Locksmith Grand Prairie
Requesting Gravatar...
I definitely feel that the information supplied is highly relevant to every person . Regards .
Left by poping on Feb 15, 2012 5:15 AM

# re: Quick PowerShell “Todo” Gmail Emailer
Requesting Gravatar...
Fantastic task ! Your internet page has presented me much of the facts and strategies I expected .

Left by Troubleshooting Windows 7 on Feb 15, 2012 7:01 AM

# re:
Requesting Gravatar...
This is a fantastic website and I can not recommend you guys enough. Full of useful resource and great layout very easy on the eyes. Please do keep up this great work.
Left by grand falls casino on Mar 09, 2012 7:48 AM

# re:
Requesting Gravatar...
I really love the way information is presented in your post. I have added you in my social bookmark…and i am waiting for your next post.
Left by casinos in hollywood on Mar 21, 2012 1:54 AM

Your comment:
 (will show your gravatar)

Copyright © Lance Robinson | Powered by: | Join free