{"id":16111,"date":"2010-12-25T00:01:00","date_gmt":"2010-12-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/12\/25\/weekend-scripter-a-windows-powershell-carol-ebenezer-script-learns-to-send-email\/"},"modified":"2010-12-25T00:01:00","modified_gmt":"2010-12-25T00:01:00","slug":"weekend-scripter-a-windows-powershell-carol-ebenezer-script-learns-to-send-email","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-a-windows-powershell-carol-ebenezer-script-learns-to-send-email\/","title":{"rendered":"Weekend Scripter: A Windows PowerShell Carol: Ebenezer Script Learns to Send Email"},"content":{"rendered":"<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<b><span style=\"font-size:10.0pt\">Summary:<\/span><\/b><span style=\"font-size:10.0pt\"> Conclusion to the Windows PowerShell Carol in which Ebenezer Script learns how to send email from inside a PowerShell script.<\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<span style=\"font-size:10.0pt\">Microsoft Scripting Guy Ed Wilson here. It is almost the end of the year and we have decided to devote some posts to the holiday season. We even have guest bloggers from around the world to share some holiday spirit. This week we have had Sean Kearney. You can learn more about Sean in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/12\/19\/weekend-scripter-holiday-powershell-carol-part-one.aspx\"><span>Monday&rsquo;s blog introduction<\/span><\/a>. Be sure to check out <a href=\"https:\/\/www.youtube.com\/watch?v=v04BXhlPxyY\">Sean&rsquo;s theme song for this week&rsquo;s PowerShell Carol posts<\/a>.<\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer awoke with a start.<\/span>\n<span style=\"font-size:10.0pt\">Light poured onto his face like a fresh hot shower. It was rejuvenating and it was invigorating. With the sudden realization that he was not a terminated process but was still alive, he was quite ENERGIZED! <\/span>\n<span style=\"font-size:10.0pt\">He quickly searched online for something fun to do. That was how he used to script. &ldquo;Passion and Joy to release the Toy,&rdquo; he muttered eyes fluttering left and right. <\/span>\n<span style=\"font-size:10.0pt\">Moments later he had himself a small script that made his name appear letter by letter. Just for fun.<\/span><\/p>\n<blockquote>\n<p><span style=\"font-family: courier new,courier\">$Phrase=&ldquo;Happy Holidays Mr. Script!&rdquo;<br \/>Foreach ($count in 0..(($Phrase.Length)-1)) { WRITE-HOST $Phrase.substring($count,1) &rdquo; &ldquo; -nonewline; start-sleep -milliseconds 100 }; WRITE-HOST<\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<span style=\"font-size:10.0pt\">It played to the screen, delighting the old master. It was a spark not seen in years.<\/span>\n<span style=\"font-size:10.0pt\">Jumping up and down like a jackrabbit, Ebenezer burst out the front door (still in boxer shorts) screaming at the top of his lungs &ldquo;I&rsquo;M USING WINDOWS POWERSHELL! I&rsquo;M USING WINDOWS POWERSHELL!&rdquo; (Strangely, he was singing it to an AC\/DC rock tune.)<\/span>\n<span style=\"font-size:10.0pt\">A few passersby looked at him oddly. But then he looked over and saw a small kid with a Zune. &ldquo;Hey, you! What time is it? Are the computer shops opened up yet?&rdquo; he yelled to the lad like a maniac.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;It is time for you to put some clothes on, Sir!&rdquo; the young fellow chattered back, &ldquo;and yes, yes the computer shops are open!&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Silly boy and truthful, too,&rdquo; mulled Ebenezer. <span>&nbsp;<\/span>Ebenezer dashed back inside to grab some swag from an old TechNet tour to put on. Back outside he yelled back.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Boy! Does the computer shop still have that honking new laptop?&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">The fellow&rsquo;s eyes lit up. &ldquo;Do you mean the new Windows 7 Tablet PC with Multitouch display, i7 Intel Quadcore chip, mirrored solid state drives, Emotive.com interface tied into Kinect?&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Yup! That&rsquo;d be the one!&rdquo; Ebenezer chortled back.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Run up the road and block anybody from buying it! I&rsquo;m about to make somebody&rsquo;s day! Do it fast and I&rsquo;ll buy you a MultiTouch netbook of your own! Stop anybody from buying it and I&rsquo;ll toss in a Windows Phone 7!&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">The kid tore off down the road like a rocket, knocking over dogs, oranges and a small Volkswagen. &ldquo;Windows Phone 7,&rdquo; he muttered with his eyes lit up like a Blue Laser mouse.<\/span>\n<span style=\"font-size:10.0pt\">Mr. Script giggled. &ldquo;Tiny Shim is to become a Chartered Accountant. Bah! I&rsquo;ll see to it such a cruel thing never happens! I&rsquo;ll encourage that wee lad.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">With that, Mr. Script went online to the Microsoft store and maxed out his Triple platinum card, four times over.<\/span>\n<span style=\"font-size:10.0pt\">The next day, Bob Snipit showed up at the office. He stumbled in dropping his copy of <i>Windows PowerShell Step by Step<\/i>.<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer looked down, pretending to be angry.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Baaaah! More of that nonsense, eh? Codebug! Come over here right now! I&rsquo;ve got a word to give to you!&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Bob shuffled over fearing the worst. Not another day of listening to him whine about, &ldquo;In my day, we didn&rsquo;t have a fancy GUI. We hard coded our own editors by flipping switches directly&hellip;&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Mr. SNIPIT!&rdquo; barked Mr. Script, &ldquo;I&rsquo;ve had enough of your flippant disregard for VBScript!<span>&nbsp; <\/span>This complete habberdash. Codebug! This WINDOWS POWERSHELL! So that&rsquo;s it! I&rsquo;m going to have to&hellip;&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Bob braced for it, fearing termination or worse; having to work in LOGO.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;&hellip;have to get you to teach it to me.&rdquo; he giggled madly throwing poor Bob for a loop as Mr. Script quipped: <\/span><\/p>\n<blockquote>\n<p><span style=\"font-family: courier new,courier\">GET-CONTENT C:BobSnipitReaction.txt<\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<span style=\"font-size:10.0pt\">Bob&rsquo;s mouth hit the floor so hard he looked like something out of an old Saturday morning cartoon.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Bob. I&rsquo;ve been a crabby old idiot. The Spirit of Scripting hit me hard last night. Over the years having to drop one technology and learn another, I did not think it so. Then last night I was visited by three spir&#8230; Well, let&rsquo;s just say I had a revelation last night. I&rsquo;d like for you to teach me the wonder of Windows PowerShell.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Bob sat stunned.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Bob, I have one more request. We&rsquo;re not going to work today. I&rsquo;d like to do something BIG in Windows PowerShell for the Holidays. Would you help me?&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Still shocked all Bob could mutter was &ldquo;uh huh.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;So Bob, I was thinking of emailing everybody a cheery greeting. But in VBScript it was difficult to send an email an e-&hellip;&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;An e-mail? That&rsquo;s a Windows PowerShell command!&rdquo; Burst out Bob, not realizing himself.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Built in, eh?&rdquo; Ebenezer blinked with delight, &ldquo;Wonderful! So how do we do this?&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Bob looked over. &ldquo;May I sir?&rdquo; reaching for the keyboard.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Go ahead&hellip;&rdquo; the old master watched with great interest.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Well Mr. Script, in Windows PowerShell to send an email I just use this command&hellip;&rdquo;<\/span><\/p>\n<blockquote>\n<p><span style=\"font-family: courier new,courier\">SEND-MAILMESSAGE<\/span><\/p>\n<\/blockquote>\n<p>&nbsp;\n<span style=\"font-size:10.0pt\">&ldquo;&hellip;and to see HOW to use it we just key in&rdquo;<\/span><\/p>\n<blockquote>\n<p><span style=\"font-family: courier new,courier\">GET-HELP SEND-MAILMESSAGE &ndash;examples<\/span><\/p>\n<\/blockquote>\n<p>&nbsp;\n<span style=\"font-size:10.0pt\">Ebenenzer blinked with delight. &ldquo;Wonderful! It has built in examples of how to use it!<span>&nbsp; <\/span>So I see from the examples to send an email to you with an attachment I just key in:&rdquo;<\/span><\/p>\n<blockquote>\n<p><span style=\"font-family: courier new,courier\">send-mailmessage -from &ldquo;Mr.Script &lt;grump@contoso.com&gt;&#8221; -to &#8220;Bob &lt;assistant@contoso.com&gt;&#8221; -subject &#8220;Happy Holidays&#8221; -body &#8220;Happy Holidays from Mr. Script&#8221; -Attachment &#8220;Picture.JPG&rdquo; -smtpServer smtp.fabrikam.com<\/span><\/p>\n<\/blockquote>\n<p>&nbsp;\n<span style=\"font-size:10.0pt\">Bob nodded. &ldquo;But here&rsquo;s the nicer part. Did you know with that same line you could send a custom email to a LIST of people? Each person receiving what appears to be a single, custom email?&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer looked up. &ldquo;Do you mean like when using a Mail Merge? You can do an email merge WITH Windows PowerShell?&rdquo; He almost fainted.<\/span>\n<span style=\"font-size:10.0pt\">Bob nodded. &ldquo;With a single text file I will call &ldquo;names.csv&rdquo; with quotes about the names and commas separating the information like this:&rdquo;<\/span><\/p>\n<blockquote>\n<p><span style=\"font-family: courier new,courier\">&ldquo;FirstName&rdquo;,&rdquo;LastName&rdquo;,&rdquo;Email&rdquo;<br \/>&ldquo;Bob&rdquo;,&rdquo;Snipit&rdquo;,&rdquo;bob@contoso.com&rdquo;<br \/>&ldquo;Shim&rdquo;,&rdquo;Snipit&rdquo;,&rdquo;tinyshim@fabrikam.com&rdquo;<br \/>&ldquo;Ebenezer&rdquo;,&rdquo;Script&rdquo;,&rdquo;grump@contoso.com&rdquo;<\/span><\/p>\n<\/blockquote>\n<p>&nbsp;\n<span style=\"font-size:10.0pt\">&ldquo;We can make single custom email to each person from your original.&rdquo;<\/span><\/p>\n<blockquote>\n<p><span style=\"font-family: courier new,courier\">IMPORT-CSV C:DataNames.csv | foreach {<\/span><\/p>\n<p><span style=\"font-family: courier new,courier\">$NameFrom=&ldquo;Mr.Script &lt;grump@contoso.com&gt;&#8221;<br \/>$NameTo=$_.Firstname+&rdquo; &ldquo;+$_.Lastname+&rdquo;&lt;&rdquo;+$_.Email+&rdquo;&gt;&rdquo;<br \/>$Subject=&rdquo;Happy Holidays &ldquo;+$_.Firstname+&rdquo;!&rdquo;<br \/>$Body=&rdquo;Hello &ldquo;+$_.Firstname+&rdquo; and have a Happy Holiday from Mr. Script!&rdquo;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier\">$File=&rdquo;C:PhotoPicture.JPG&rdquo;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier\">send-mailmessage -from $NameFrom -to $NameTo<span>&nbsp; <\/span>-subject $Subject -body $Body -Attachment $File -smtpServer smtp.fabrikam.com<\/span><\/p>\n<p><span style=\"font-family: courier new,courier\">}<\/span><\/p>\n<\/blockquote>\n<p>&nbsp;\n<span style=\"font-size:10.0pt\">Ebenezer blinked with great delight. He could not wait to start scripting!<\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<h3>Epilogue<\/h3>\n<p><span style=\"font-size:10.0pt\">And so the Spirit of Scripting took hold of Ebenezer. He dived into Windows PowerShell with a passion and became one of the most enjoyable people to deal with afterwards, soon becoming a great Presenter and Microsoft MVP.<\/span>\n<span style=\"font-size:10.0pt\">Bob SnipIt never lost his passion for scripting and soon was hired as a Microsoft Scripting Guy. He moved to Redmond, Washington from his little shack outside Toronto, Ontario. He occasionally hummed tunes, but to his wife (and the Community&rsquo;s) great delight; quietly wrote poetry instead.<\/span>\n<span style=\"font-size:10.0pt\">Tiny Shim? How could we forget Tiny Shim? Chartered Accountancy never did claim him.<\/span>\n<span style=\"font-size:10.0pt\">With that honking new laptop, Mr. Script bought him? That wee lad lit into his gift with a passion never seen before by humanity. He leapt beyond scripting and became one of the most Gifted Windows PowerShell Architects ever, sending inspiration everywhere with his passion for technology.<\/span>\n<span style=\"font-size: x-small\">A<\/span><span style=\"font-size:10.0pt\">s Tiny Shim Tweeted one day:<\/span><\/p>\n<blockquote><p>  <span style=\"font-family: courier new,courier\">GET-WORLD | SEND-GREETING &lsquo;May we never lose sight of our passions and always see a better day.&rsquo; <\/span><\/p>\n<\/blockquote>\n<p>&nbsp;\n<span style=\"font-size:10.0pt\">Happy Holidays everyone, and may you never forget the Spirit of Scripting! Write scripts in whatever language suits you best but never forget the joy of your first line of code. Never lose sight of your passion.<\/span>\n<span style=\"font-size:10.0pt\">Thank you Sean for this week&rsquo;s &ldquo;A Windows PowerShell Carol.&rdquo; Join us tomorrow as we wrap up Holiday Guest Blogger week with a most excellent post from Microsoft Premier Field Engineer (PFE) Chris Bell&eacute;e from the land down under. That is right, Chris will join us from Australia. <\/span>\n<span style=\"font-size:10.0pt\">I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a target=\"_blank\" href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\">scripter@microsoft.com<\/a> or post them on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><b><span style=\"font-size:10.0pt\">Ed Wilson, Microsoft Scripting Guy<\/span><\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp; Summary: Conclusion to the Windows PowerShell Carol in which Ebenezer Script learns how to send email from inside a PowerShell script. &nbsp; Microsoft Scripting Guy Ed Wilson here. It is almost the end of the year and we have decided to devote some posts to the holiday season. We even have guest bloggers from [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,28,3,154,182,61,45],"class_list":["post-16111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-messaging-and-communication","tag-scripting-guy","tag-sean-kearney","tag-sending-email","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp;&nbsp; Summary: Conclusion to the Windows PowerShell Carol in which Ebenezer Script learns how to send email from inside a PowerShell script. &nbsp; Microsoft Scripting Guy Ed Wilson here. It is almost the end of the year and we have decided to devote some posts to the holiday season. We even have guest bloggers from [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=16111"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16111\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=16111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=16111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=16111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}