{"id":1229,"date":"2011-03-17T09:00:02","date_gmt":"2011-03-17T13:00:02","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1229"},"modified":"2011-03-14T10:23:14","modified_gmt":"2011-03-14T14:23:14","slug":"st-patricks-bar-order","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/","title":{"rendered":"St. Patrick&#8217;s Bar Order"},"content":{"rendered":"<p>Let's have a little fun with St. Patrick's Day and perhaps even learn a little PowerShell.<!--more--><\/p>\n<p>Imagine, and this might be hard I know, that you are in a bar on St. Patrick's Day with a friend. But you can't think of what to order. Or perhaps you've been there too long and can't make a rational decision. Fortunately you can still run a simple PowerShell script on your netbook.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n#requires -version 2.0<\/p>\n<p>#define an array of beverage choices<br \/>\n$drinks=@(<br \/>\n\"beer\",\"Guiness\",\"milk\",<br \/>\n\"rootbeer\",\"whiskey\",<br \/>\n\"water\",\"wine cooler\",<br \/>\n\"porter\",\"ale\",\"hard lemonade\",<br \/>\n\"chablis\",\"shot\")<\/p>\n<p>#get two random elements from the array<br \/>\n$choice=$drinks | get-random -count 2<br \/>\n#choice is also an array. I'll make my drink order the first element<br \/>\n$mydrink=$choice[0]<br \/>\n#my friend get's the second element.<br \/>\n$yourdrink=$choice[1]<\/p>\n<p>#construct a string message using the -f operator<br \/>\n$msg=\"I'll take another {0} and a nice {1} for my friend.\" -f $mydrink,$yourdrink<\/p>\n<p>#display the message<br \/>\nWrite-Host $msg -ForegroundColor Green<br \/>\n[\/cc]<\/p>\n<p>The script defines an array of drink choices. Using the @() construct is an explicit way of defining an array. I could have easily used a comma separated list of strings.  The main part of the script is deciding what to drink. The drink array is piped to the Get-Random cmdlet which returns a 2 values. The $choice variable is also an array. I use the [] to reference an element by index number. I'll assign the first element, always start at 0, to my drink order and the second element to my friend's.<\/p>\n<p>Next I need to construct a string. In this example I wanted to use the -f format operator. This is a great technique when you need to construct complex strings with variables. Don't try to concatenate. The place holders like {0}, will be replaced with the correponding value on the right side of the -f operator.<\/p>\n<p>All that's left is to place my order. I use Write-Host which only writes to the console., which is fine for my purposes. Although, as an added bonus I could take advantage of the terrific text to speech engine in Windows 7 and also \"speak\" my order to the bartender.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n#optionally speak it<br \/>\n$Voice=New-Object -ComObject \"SAPI.SPVoice\"<br \/>\n$voice.speak($msg) | out-Null<br \/>\n[\/cc]<\/p>\n<p>The $voice object has a few other properties you can tweak. Pipe the object to Get-Member to see for yourself. By the way, I pipe the output from the Speak() method to Out-Null to suppress the integer output.<\/p>\n<p>If you'd like to try this out, download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/03\/BarOrder.txt'>BarOrder.ps1<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s have a little fun with St. Patrick&#8217;s Day and perhaps even learn a little PowerShell.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[233,245,534],"class_list":["post-1229","post","type-post","status-publish","format-standard","hentry","category-powershell","tag-arrays","tag-get-random","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>St. Patrick&#039;s Bar Order &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"St. Patrick&#039;s Bar Order &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Let&#039;s have a little fun with St. Patrick&#039;s Day and perhaps even learn a little PowerShell.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-03-17T13:00:02+00:00\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"St. Patrick&#8217;s Bar Order\",\"datePublished\":\"2011-03-17T13:00:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/\"},\"wordCount\":436,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"arrays\",\"Get-Random\",\"PowerShell\"],\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/\",\"name\":\"St. Patrick's Bar Order &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2011-03-17T13:00:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1229\\\/st-patricks-bar-order\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"St. Patrick&#8217;s Bar Order\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"St. Patrick's Bar Order &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/","og_locale":"en_US","og_type":"article","og_title":"St. Patrick's Bar Order &#8226; The Lonely Administrator","og_description":"Let's have a little fun with St. Patrick's Day and perhaps even learn a little PowerShell.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-03-17T13:00:02+00:00","author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"St. Patrick&#8217;s Bar Order","datePublished":"2011-03-17T13:00:02+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/"},"wordCount":436,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["arrays","Get-Random","PowerShell"],"articleSection":["PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/","name":"St. Patrick's Bar Order &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2011-03-17T13:00:02+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1229\/st-patricks-bar-order\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"St. Patrick&#8217;s Bar Order"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1307,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1307\/friday-fun-powershell-pep-talk\/","url_meta":{"origin":1229,"position":0},"title":"Friday Fun PowerShell Pep Talk","author":"Jeffery Hicks","date":"April 1, 2011","format":false,"excerpt":"Today's Friday Fun is meant to help get you excited about the upcoming Scripting Games. I want to add a little pep to your PowerShell prompt. Perhaps it will even keep you motivated. What I have for you today are variety of prompt functions. Consider them variations on a theme.\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"PowerShell Pep Talk","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/04\/color-pep-prompt-300x144.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1389,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1389\/friday-fun-randomness-abounds\/","url_meta":{"origin":1229,"position":1},"title":"Friday Fun Randomness Abounds","author":"Jeffery Hicks","date":"April 29, 2011","format":false,"excerpt":"I find it a little ironic that although I like efficiency, structure and order I'm fascinated with randomness. In today's Friday Fun I want to explore a few ways you might incorporate randomness into your PowerShell scripting. Perhaps you need a random number between 100 and 500. Or a string\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":940,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/940\/friday-fun-playing-with-strings\/","url_meta":{"origin":1229,"position":2},"title":"Friday Fun Playing with Strings","author":"Jeffery Hicks","date":"September 17, 2010","format":false,"excerpt":"While I was busy working, it turned into Friday which means time for a little PowerShell fun. I can't say you'll find any deep, meaningful, production use from today's post, but you might pick up a few techniques, which is really the point. Today we're going to have some fun\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1085,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1085\/friday-fun-lets-play-bingo\/","url_meta":{"origin":1229,"position":3},"title":"Friday Fun: Let&#8217;s Play Bingo!","author":"Jeffery Hicks","date":"January 28, 2011","format":false,"excerpt":"Today Campers we're playing Bingo. Or at least getting ready to. This week I have some PowerShell code that will create a BINGO card. For those of you outside of North America you might need to take a crash course on this game. But even if you don't play, this\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4661,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4661\/friday-fun-learning-from-spam\/","url_meta":{"origin":1229,"position":4},"title":"Friday Fun Learning from Spam","author":"Jeffery Hicks","date":"December 11, 2015","format":false,"excerpt":"Today's article is definitely on the amusing side, although hopefully it will make for an interesting learning opportunity. Earlier this week I was clearing out spam on my blog and found a comment that looked like the spammer's template file. The comment contained a number of short entries like this:\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1554,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1554\/friday-fun-powershell-powerball-numbers\/","url_meta":{"origin":1229,"position":5},"title":"Friday Fun PowerShell PowerBall Numbers","author":"Jeffery Hicks","date":"July 8, 2011","format":false,"excerpt":"Like many of you, I dream about hitting the lottery and retiring to live the good life. Unfortunately I rarely play so I guess my odds are winning are pretty slim. But for the latest installment of Friday Fun, I thought I would have PowerShell help me pick some numbers\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1229"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1229\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}