Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell here-strings to create an ASCII holiday snow person.
Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I returned from our European tour yesterday, just in time for the Windows PowerShell users group in Charlotte. Yesterday, we did a script share type of event where everyone brought a script to share with the other members of the group.
Note By the way, the Scripting Guys holiday series this year is written by honorary Scripting Guy and Microsoft PowerShell MVP Sean Kearney. It begins on December 21, 2012, and is called “It’s a Wonderful Shell.” Here is a video teaser to help get you in the spirit of things.
While Teresa and I were in Warsaw, we had the opportunity to visit with Microsoft PowerShell MVP Bartek Bielawski. One evening, we went into the old town and took pictures. Here is a picture of an old castle in the square. It was awesome seeing the moving snowflakes on the side. Way cool stuff.
Use Windows PowerShell here-strings to simplify strings
Well, anyway, I thought it was a good inspiration to create a silly sort of Windows PowerShell script. By using a here-string, it is really easy to do ASCII art in Windows PowerShell. All I need to do is to store the ASCII art into a here-string and store the result in a variable. Next, I simply display the contents of the variable.
A here-string is much more useful than simply creating snow persons. For example, if you have a complicated connection string that may contain special characters, a here-string is a perfect answer. If you have a string you will invoke to run a complicated switch-induced command line, then a here-string may be a good solution as well. Anyway, here is the New-SnowPerson.ps1 script.
$snowowerson = @”
________
* [________] . *
* . |________| / . *
| |/
* =========
* ______________
* |||||| / \
||> || ( 0 0 ) .
. ||- | | O |
|||||| \ {—} / *
* \====/ [~~~~~~~~~]
\\// _/====||=====\_
_||-‘`/ || \`’-._ *
* .-` )| ; || ; ‘.
/ `–.| || | `\
| \ || |-, \ .
* \ .; \/ ; |_, |
`”’||` ,\ 0 /, `.__/
||.` ‘. 0 .’ `. *
* || ` ‘ ‘ ` \
|| ;
. * || | .
|| | *
@ || | @
.__.-“”-.__.-“””|| ;.-“””-.__.-“”-.__.
|| /
||’. .’
|| ‘-._ _ _ _ _.-‘
“@
Clear-Host
$snowowerson
When I run the script in the Windows PowerShell console, the following appears.
Join me tomorrow for more cool Windows PowerShell stuff.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy
0 comments