{"id":3665,"date":"2014-01-31T13:34:41","date_gmt":"2014-01-31T18:34:41","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=3665"},"modified":"2014-01-31T13:34:41","modified_gmt":"2014-01-31T18:34:41","slug":"friday-fun-messagebox-writer","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/","title":{"rendered":"Friday Fun: Messagebox Writer"},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png\" alt=\"yellowsub\" width=\"185\" height=\"139\" class=\"alignleft size-full wp-image-3666\" \/><\/a> For today's fun I'm revisiting a topic I'm sure I've written about in the past and that is creating a graphical message box in PowerShell. There are a few ways you can do this from using the Visual Basic classes, the old standard WScript.Shell object from VBScript or using WinForms. They all basically work the same way and you probably can't tell from the message box what was used to create it. So I took my version of New-MessageBox which uses the Visual Basic interaction class and updated it a bit.<\/p>\n<p>Here's the new function.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n#requires -version 3.0\r\n\r\nFunction New-Messagebox {\r\n\r\n&lt;#\r\n.SYNOPSIS\r\nDisplay a VisualBasic style message box.\r\n\r\n.DESCRIPTION\r\nThis function will display a graphical messagebox, like the one from VisualBasic\r\nor VBScript. You must specify a message. The default button is OKOnly and the \r\ndefault icon is for Information. If you want to use the value from a button click\r\nin a PowerShell expression, use the -Passthru parameter.\r\n\r\nThe message box will remain displayed until the user clicks a button. The box may \r\nalso not appear on top, but if you have audio enabled you should hear the Windows \r\nexclamation sound.\r\n\r\nAs an added bonus you can use the -Voice parameter to hear the prompt spoken aloud.\r\n\r\n.PARAMETER Message\r\nThe text to display. Keep it short. The command will throw an exception if the\r\nmessage length is greater than 800.\r\n\r\n.PARAMETER Button\r\nThe button set to display. The default is OKOnly. Possible values are:\r\n    OkOnly\r\n    OkCancel\r\n    AbortRetryIgnore\r\n    YesNoCancel\r\n    YesNo\r\n    RetryCancel\r\n\r\n.PARAMETER Icon\r\nThe icon to display. The default is Information. Possible values are:\r\n    Critical\r\n    Question\r\n    Exclamation\r\n    Information\r\n\r\n.PARAMETER Title\r\nThe message box title. The default is no title. The title should be less than \r\n60 characters long, otherwise it will be truncated. Shorter is always better.\r\n\r\n.PARAMETER Passthru\r\nUse this parameter if you want the button value to be passed to the pipeline.\r\n\r\n.PARAMETER Voice\r\nUse text to speech to announce the prompt. This parameter has an alias of Speak.\r\n\r\n.EXAMPLE\r\n.Parameter VoiceGender\r\nThe command will use the default voice. Or you can specify either a Male or Female\r\nvoice. This parameter will have no affect unless you also use -Voice. This \r\nparameter has an alias of Gender.\r\n\r\n.EXAMPLE\r\nPS C:\\&gt; New-Messagebox \"Time to go home!\"\r\nDisplay a message box with no title and the OK button.\r\n\r\n.EXAMPLE \r\nPS C:\\&gt; $rc= New-Messagebox -message \"Do you know what you're doing?\" -icon exclamation -button \"YesNoCancel\" -title \"Hey $env:username!!\" -passthru\r\nSwitch ($rc) {\r\n \"Yes\" {\"I hope your resume is up to date.\"}\r\n \"No\" {\"Wise move.\"}\r\n \"Cancel\" {\"When in doubt, punt.\"}\r\n Default {\"nothing returned\"}\r\n}\r\n\r\n.EXAMPLE\r\nPS C:\\&gt; New-MessageBox -message \"Are you the walrus?\" -icon question -title \"Hey, Jude\" -button YesNo -voice\r\n\r\nDisplay the message box and speak the message.\r\n\r\n.NOTES\r\nVersion      : 2.0\r\nLast Updated : 1\/30\/2014\r\n\r\nLearn more:\r\n  PowerShell in Depth: An Administrator's Guide\r\n  PowerShell Deep Dives\r\n  Learn PowerShell 3 in a Month of Lunches \r\n  Learn PowerShell Toolmaking in a Month of Lunches \r\n \r\n\r\n  ****************************************************************\r\n  * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *\r\n  * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK.  IF   *\r\n  * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *\r\n  * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.             *\r\n  ****************************************************************\r\n\r\n\"Those who forget to script are doomed to repeat their work.\"\r\n\r\n.LINK\r\nhttp:\/\/jdhitsolutions.com\/blog\/\r\n\r\n.INPUTS\r\nNone\r\n.OUTPUTS\r\n[system.string]\r\n\r\n#&gt;\r\n\r\n[cmdletbinding()]\r\n\r\nParam (\r\n[Parameter(Position=0,Mandatory=$True,\r\nHelpMessage=\"Specify a display message or prompt for the message box\",\r\nValueFromPipelinebyPropertyName=$True)]\r\n[ValidateNotNullorEmpty()]\r\n[Alias(\"prompt\")]\r\n[ValidateScript({\r\n if ($_.length -gt 800) {\r\n   Throw \"Keep the message to less than 800 characters\"\r\n }\r\n else {\r\n    $True\r\n }\r\n})]\r\n[string]$Message,\r\n\r\n[Parameter(ValueFromPipelinebyPropertyName=$True)]\r\n[ValidateSet(\"OkOnly\",\"OkCancel\",\"AbortRetryIgnore\",\"YesNoCancel\",\"YesNo\",\"RetryCancel\")]\r\n[string]$Button=\"OkOnly\",\r\n\r\n[Parameter(ValueFromPipelinebyPropertyName=$True)]\r\n[ValidateSet(\"Critical\", \"Question\", \"Exclamation\", \"Information\")]\r\n[string]$Icon=\"Information\",\r\n[ValidateScript({\r\n if ($_.length -gt 60) {\r\n   Throw \"Keep the title to less than 60 characters\"\r\n }\r\n else {\r\n    $True\r\n }\r\n})]\r\n[Parameter(ValueFromPipelinebyPropertyName=$True)]\r\n[string]$Title,\r\n\r\n[Parameter(ValueFromPipelinebyPropertyName=$True)]\r\n[switch]$Passthru,\r\n\r\n[Parameter(ValueFromPipelinebyPropertyName=$True)]\r\n[Alias(\"Speak\")]\r\n[switch]$Voice,\r\n\r\n[Parameter(ValueFromPipelinebyPropertyName=$True)]\r\n[ValidateSet(\"Male\",\"Female\")]\r\n[Alias(\"Gender\")]\r\n[string]$VoiceGender\r\n\r\n)\r\n\r\nWrite-Verbose \"Starting $($myinvocation.MyCommand)\"\r\nWrite-Verbose \"Title = $Title\"\r\nWrite-Verbose \"Icon = $icon\"\r\nWrite-Verbose \"Button = $Button\"\r\nWrite-Verbose \"Message = $Message\"\r\n\r\n\r\nTry { \r\n    Write-Verbose \"Loading VisualBasic assembly\"\r\n    #load the necessary assembly\r\n    Add-Type -AssemblyName \"Microsoft.VisualBasic\" -ErrorAction Stop     \r\n    if ($voice) {\r\n        Write-Verbose \"Loading speech assembly\"\r\n        Try { \r\n            #load the necessary assembly\r\n            Add-Type -assembly system.speech -ErrorAction Stop\r\n            $synth = new-object System.Speech.Synthesis.SpeechSynthesizer -ErrorAction Stop\r\n            if ($VoiceGender) {\r\n                Write-Verbose \"Selecting a $voiceGender voice\"\r\n                $synth.SelectVoiceByHints($VoiceGender)\r\n            }\r\n            else {\r\n                Write-Verbose \"Using default voice\"\r\n            }\r\n            $synth.SpeakAsync($message) | Out-Null\r\n        }\r\n        Catch {\r\n            Write-Warning \"Failed to add System.Speech assembly or create the SpeechSynthesizer object.\"\r\n            Write-Warning $error[0].Exception.Message\r\n            #bail out\r\n            Return\r\n        }\r\n    } #if $voice    \r\n    \r\n    #create the message box using the parameter values\r\n    #Whatever button the user clicks will be the return value\r\n    $returnValue = [microsoft.visualbasic.interaction]::Msgbox($message,\"$button,$icon\",$title)\r\n}\r\nCatch {\r\n    Write-Warning \"Failed to add Microsoft.VisualBasic assembly or create the messagebox.\"\r\n    Write-Warning $error[0].Exception.Message\r\n}\r\n#write return value if -Passthru is called\r\nif ($Passthru) {\r\n    Write-Verbose \"Passing return value from message box\"\r\n    Write-Output $returnValue\r\n}\r\n\r\nWrite-Verbose \"Ending $($myinvocation.MyCommand)\"\r\n\r\n} #end function\r\n\r\n#set an optional alias\r\nSet-Alias -name nmb -Value New-Messagebox<\/pre>\n<p>This version has been tweaked to include better parameter validation. I also modified it so that the parameters accept pipeline input by property name. I think the function is pretty well documented so I won't spend much time discussing it. You can try it out for yourself.  Be sure to test with bad parameter values so you can see how validation works. <\/p>\n<p>If you had grabbed an older version of this function, there is one breaking change. In the past I think I had the function always write the clicked button value to the pipeline. Now the function doesn't write anything to the pipeline unless you use -Passthru. When you run a command like this:<\/p>\n<pre class=\"lang:ps decode:true \" >new-messagebox -Title \"Friday Fun\" -Message \"Do you think PowerShell is fun?\" -Icon Question -Button YesNo<\/pre>\n<p>You will get this:<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/MsgBoxYesNo.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/MsgBoxYesNo.png\" alt=\"MsgBoxYesNo\" width=\"286\" height=\"172\" class=\"aligncenter size-full wp-image-3667\" \/><\/a><\/p>\n<p>Nothing will be written to the pipeline because I didn't use -Passthru. Now for the extra-fun part. If you read through the code listing, you may have seen references to a speech assembly. I figured, why not include an option to have the message spoken aloud? So I'm using the System.Speech.Synthesis.SpeechSynthesizer class to speak the text in the message box. Use the -Voice parameter to turn this on. PowerShell will use the default voice for your system. But wait, there's more! I also included a second parameter, VoiceGender, so that you can specify if you want a Male or Female voice. On later client operating systems I believe you get one of each automatically. <\/p>\n<div style=\"width: 640px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-3665-1\" width=\"640\" height=\"205\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/demo-messagebox.mp4?_=1\" \/><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/demo-messagebox.mp4\">http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/demo-messagebox.mp4<\/a><\/video><\/div>\n<p>Click <a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/demo-messagebox.mp4\" title=\"save the mp4 file\" target=\"_blank\">here<\/a> to view the video full size or right-click and save the video clip. <\/p>\n<p>Here's the sample script I ran.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n#requires -version 3.0\r\n\r\n#dot source the New-MessageBox function\r\n\r\n. C:\\scripts\\New-MessageBox.ps1\r\n\r\n$r = New-Messagebox -Message \"Are you the walrus?\" -Title \"Hey Jude\" -Icon Question -Button YesNo -Voice -VoiceGender Female -Passthru\r\n\r\nIf ($r -eq \"Yes\") {\r\n    Write-Host \"Excellent! goo goo g'joob.\" -ForegroundColor Green\r\n}\r\nelse {\r\n    $r = New-Messagebox -Message \"Are you the eggman?\" -Title \"Hey Jude\" -Icon Question -Button YesNo -Voice -VoiceGender Female -Passthru\r\n    if ($r -eq \"Yes\") {\r\n        Write-Host \"Excellent! They are the eggmen.\" -ForegroundColor Green\r\n    }\r\n    else {\r\n        Write-Host \"Bummer. Let it be.\" -ForegroundColor Yellow\r\n    }\r\n}\r\n<\/pre>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For today&#8217;s fun I&#8217;m revisiting a topic I&#8217;m sure I&#8217;ve written about in the past and that is creating a graphical message box in PowerShell. There are a few ways you can do this from using the Visual Basic classes, the old standard WScript.Shell object from VBScript or using WinForms. They all basically work the&#8230;<\/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":"New Friday Fun: #PowerShell Messagebox Writer http:\/\/wp.me\/p1nF6U-X7","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[271,4,8],"tags":[568,259,534,540,451],"class_list":["post-3665","post","type-post","status-publish","format-standard","hentry","category-friday-fun","category-powershell","category-scripting","tag-friday-fun","tag-messagebox","tag-powershell","tag-scripting","tag-speech"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun: Messagebox Writer &#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\/3665\/friday-fun-messagebox-writer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun: Messagebox Writer &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"For today&#039;s fun I&#039;m revisiting a topic I&#039;m sure I&#039;ve written about in the past and that is creating a graphical message box in PowerShell. There are a few ways you can do this from using the Visual Basic classes, the old standard WScript.Shell object from VBScript or using WinForms. They all basically work the...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-31T18:34:41+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png\" \/>\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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun: Messagebox Writer\",\"datePublished\":\"2014-01-31T18:34:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/\"},\"wordCount\":383,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/yellowsub.png\",\"keywords\":[\"Friday Fun\",\"MessageBox\",\"PowerShell\",\"Scripting\",\"Speech\"],\"articleSection\":[\"Friday Fun\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/\",\"name\":\"Friday Fun: Messagebox Writer &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/yellowsub.png\",\"datePublished\":\"2014-01-31T18:34:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#primaryimage\",\"url\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/yellowsub.png\",\"contentUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/yellowsub.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3665\\\/friday-fun-messagebox-writer\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Friday Fun\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/friday-fun\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun: Messagebox Writer\"}]},{\"@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":"Friday Fun: Messagebox Writer &#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\/3665\/friday-fun-messagebox-writer\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun: Messagebox Writer &#8226; The Lonely Administrator","og_description":"For today's fun I'm revisiting a topic I'm sure I've written about in the past and that is creating a graphical message box in PowerShell. There are a few ways you can do this from using the Visual Basic classes, the old standard WScript.Shell object from VBScript or using WinForms. They all basically work the...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/","og_site_name":"The Lonely Administrator","article_published_time":"2014-01-31T18:34:41+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun: Messagebox Writer","datePublished":"2014-01-31T18:34:41+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/"},"wordCount":383,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png","keywords":["Friday Fun","MessageBox","PowerShell","Scripting","Speech"],"articleSection":["Friday Fun","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/","name":"Friday Fun: Messagebox Writer &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png","datePublished":"2014-01-31T18:34:41+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#primaryimage","url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png","contentUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/yellowsub.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3665\/friday-fun-messagebox-writer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Friday Fun","item":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},{"@type":"ListItem","position":2,"name":"Friday Fun: Messagebox Writer"}]},{"@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":3004,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3004\/powershell-messagebox\/","url_meta":{"origin":3665,"position":0},"title":"PowerShell Messagebox","author":"Jeffery Hicks","date":"May 8, 2013","format":false,"excerpt":"Recently I posted an article explaining how to create a popup box in PowerShell using the Wscript.Shell COM object from our VBScript days. That was something I presented at the PowerShell Summit. Another option is a MessageBox, again like we used to use in VBScript. This works very much like\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"messagebox","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/messagebox-300x147.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1185,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1185\/friday-fun-get-messagebox\/","url_meta":{"origin":3665,"position":1},"title":"Friday Fun Get MessageBox","author":"Jeffery Hicks","date":"March 4, 2011","format":false,"excerpt":"Today's Friday Fun offers a way for you to graphically interact with your PowerShell scripts and functions without resorting to a lot of complex Winform scripting. I have a function that you can use to display an interactive message box complete with buttons like Yes, No or Cancel. You can\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":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/03\/msgbox.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2016,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2016\/friday-fun-a-powershell-alarm-clock\/","url_meta":{"origin":3665,"position":2},"title":"Friday Fun: A PowerShell Alarm Clock","author":"Jeffery Hicks","date":"January 20, 2012","format":false,"excerpt":"Today's Friday Fun is a continuation of my exploration of ways to use Start-Job. A few weeks ago I wrote about using Start-Job to create \"scheduled\" tasks. I realized I could take this further and turn this into a sort of alarm clock. The goal is to execute at command\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":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/01\/new-alarm-help-300x197.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2976,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2976\/powershell-popup\/","url_meta":{"origin":3665,"position":3},"title":"PowerShell PopUp","author":"Jeffery Hicks","date":"April 29, 2013","format":false,"excerpt":"At the recent PowerShell Summit I presented a session on adding graphical elements to your script without the need for WinForms or WPF. One of the items I demonstrated is a graphical popup that can either require the user to click a button or automatically dismiss after a set time\u2026","rel":"","context":"In &quot;Conferences&quot;","block_context":{"text":"Conferences","link":"https:\/\/jdhitsolutions.com\/blog\/category\/conferences\/"},"img":{"alt_text":"popup","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/popup-300x139.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4011,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4011\/friday-fun-a-popup-alternative\/","url_meta":{"origin":3665,"position":4},"title":"Friday Fun &#8211; A Popup Alternative","author":"Jeffery Hicks","date":"September 12, 2014","format":false,"excerpt":"In the past I've written and presented about different ways to add graphical elements to your PowerShell scripts that don't rely on Windows Forms or WPF. There's nothing wrong with those techniques, but they certainly require some expertise and depending on your situation may be overkill. So let's have some\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"windowpane-thumbnail","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/09\/windowpane-thumbnail.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1136,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1136\/friday-fun-snappy-shortcuts\/","url_meta":{"origin":3665,"position":5},"title":"Friday Fun &#8211; Snappy Shortcuts","author":"Jeffery Hicks","date":"February 11, 2011","format":false,"excerpt":"In one of my recent Prof. PowerShell columns, I wrote about using the Wscript.Shell VBScript object in PowerShell to retrieve special folder paths. Another handy trick is the ability to create shortcut links to either file or web resources. Let me show you how to accomplish this in PowerShell and\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":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/02\/create-shortcuts-300x185.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3665","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=3665"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3665\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}