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. smtp.gmail.com, 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.