{"id":346,"date":"2009-09-01T09:36:00","date_gmt":"2009-09-01T13:36:00","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/2009\/09\/powershell-exit-stage-left\/"},"modified":"2009-09-01T09:36:00","modified_gmt":"2009-09-01T13:36:00","slug":"powershell-exit-stage-left","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/","title":{"rendered":"Powershell: Exit Stage Left"},"content":{"rendered":"<p>While reviewing and revising the manuscript for <a title=\"Visit SAPIENPress.com to learn more\" href=\"http:\/\/www.sapienpress.com\/powershell3.asp\" target=\"_blank\">Windows PowerShell v2.0: TFM 3rd ed<\/a>. I had the opportunity to revisit our chapter on working with events in PowerShell. An <em>event<\/em> in Windows is when something happens like a mouse-click, a process being created or window resized. In PowerShell you can easily watch for an event of interest and then do something when it happens or <em>fires<\/em>. This is referred to as an <em>event subscription<\/em>. <\/p>\n<p>PowerShell v2.0 has a few event related cmdlets you can use for creating an event subscription: <strong>Register-WMIEvent<\/strong>, <strong>Register-ObjectEvent<\/strong> and <strong>Register-EngineEvent<\/strong>. Today I want to show you something I think you might find helpful using the last cmdlet in the list.<\/p>\n<p><strong><a title=\"Get online cmdlet help\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=135243\" target=\"_blank\">Register-EngineEvent<\/a><\/strong> is used to to subscribe to Powershell related events such as when PowerShell is exiting. I\u2019ve been asked in the past if PowerShell has a shutdown script mechanism and it doesn\u2019t. But you can create your own with this cmdlet.<\/p>\n<p>The cmdlet needs the sourceid of the event and a script block that will execute when the event fires.,<\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Consolas\">PS C:\\&gt; register-engineevent PowerShell.Exiting \u2013action {write-host &quot;Au revoir, adios and good-bye&quot; \u2013foregroundcolor Green}<\/font><\/p>\n<p>Run this in your PowerShell session and you should see a new event subscription.<\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Consolas\">PS C:\\&gt; Get-EventSubscriber <\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Consolas\">SubscriptionId&#160;&#160; : 1      <br \/>SourceObject&#160;&#160;&#160;&#160; :       <br \/>EventName&#160;&#160;&#160;&#160;&#160;&#160;&#160; :       <br \/>SourceIdentifier : PowerShell.Exiting       <br \/>Action&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : System.Management.Automation.PSEventJob       <br \/>HandlerDelegate&#160; :       <br \/>SupportEvent&#160;&#160;&#160;&#160; : False       <br \/>ForwardEvent&#160;&#160;&#160;&#160; : False<\/font><\/p>\n<p>Type Exit to close PowerShell and you should briefly see your logoff message. Are you starting to get some ideas?<\/p>\n<p>Obviously you don\u2019t want to have to recreate the event subscription every time you start PowerShell, so add it to your PowerShell profile. Here\u2019s something I\u2019ve been trying lately.<\/p>\n<div style=\"border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px\" id=\"codeSnippetWrapper\">\n<div style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\" id=\"codeSnippet\">\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum1\">   1:<\/span> <span style=\"color: #008000\">#register PowerShell closing event<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum2\">   2:<\/span> Register-EngineEvent <span style=\"color: #006080\">&quot;PowerShell.Exiting&quot;<\/span> -action { <\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum3\">   3:<\/span> <span style=\"color: #008000\">#uncomment to run the shutdown script<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum4\">   4:<\/span> <span style=\"color: #008000\"># c:\\scripts\\posh\\psexit.ps1<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum5\">   5:<\/span>   $voice.speak((<span style=\"color: #006080\">&quot;Good-bye Jeff&quot;<\/span>)) | Out-Null<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum6\">   6:<\/span>   Write-Host <span style=\"color: #006080\">&quot;Bye!!&quot;<\/span> -foregroundcolor green<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum7\">   7:<\/span>   <\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum8\">   8:<\/span>   $msg=<span style=\"color: #006080\">&quot;{0} Exiting PowerShell. Total Session Time {1}&quot;<\/span> -f `<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum9\">   9:<\/span>   (get-date),((get-date) - (ps -id $pid).starttime).tostring()<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum10\">  10:<\/span>   <\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum11\">  11:<\/span>   $msg | Add-Content <span style=\"color: #006080\">&quot;$env:temp\\pshlog.txt&quot;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"><span style=\"color: #606060\" id=\"lnum12\">  12:<\/span>   } | Out-Null<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>As you can see the Action scriptblock can be as long as you need it. I have commented out for right now a line that executes a shutdown script. I can modify this script as needed to do tasks such as exporting history, aliases or whatever and it will run whenever PowerShell exits. <\/p>\n<p>I like my computer to be friendly so I have it speak to me, I use the SAPI.SPVoice object earlier in my profile to create $voice. If I have the speakers turned down, I\u2019ll at least see a message written to the screen. The last item is creating a log file in my temp directory that simply stores the current date and time and a timespan object indicating how long my PowerShell session was running.<\/p>\n<p>The entire <strong>Register-EngineEvent<\/strong> expression is piped to <strong>Out-Null<\/strong> simply to supress the output object.<\/p>\n<p>Of course there are caveats. This doesn\u2019t work with PowerShell ISE or most likely other applications that host PowerShell, although perhaps you\u2019ll test and let me know. The event also won\u2019t fire if you kill the PowerShell process or close the window using the window control. You must type \u2018Exit\u2019 to trigger the event which will kick off your action scriptblock.<\/p>\n<p>Does this look interesting? How do you think you could take advantage of this? What types of exiting actions are you using? I hope you\u2019ll share.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While reviewing and revising the manuscript for Windows PowerShell v2.0: TFM 3rd ed. I had the opportunity to revisit our chapter on working with events in PowerShell. An event in Windows is when something happens like a mouse-click, a process being created or window resized. In PowerShell you can easily watch for an event of interest and then do something when it happens or fires. This is referred to as an event subscription. <\/p>\n<p>PowerShell v2.0 has a few event related cmdlets you can use for creating an event subscription: Register-WMIEvent, Register-ObjectEvent and Register-EngineEvent. Today I want to show you something I think you might find helpful using the last cmdlet in the list.<\/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":[72,75,8],"tags":[81,534,84,83,82,540],"class_list":["post-346","post","type-post","status-publish","format-standard","hentry","category-commandline","category-powershell-v2-0","category-scripting","tag-event","tag-powershell","tag-profile","tag-register-engineevent","tag-scriptblock","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Powershell: Exit Stage Left &#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\/scripting\/346\/powershell-exit-stage-left\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Powershell: Exit Stage Left &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"While reviewing and revising the manuscript for Windows PowerShell v2.0: TFM 3rd ed. I had the opportunity to revisit our chapter on working with events in PowerShell. An event in Windows is when something happens like a mouse-click, a process being created or window resized. In PowerShell you can easily watch for an event of interest and then do something when it happens or fires. This is referred to as an event subscription.  PowerShell v2.0 has a few event related cmdlets you can use for creating an event subscription: Register-WMIEvent, Register-ObjectEvent and Register-EngineEvent. Today I want to show you something I think you might find helpful using the last cmdlet in the list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2009-09-01T13:36:00+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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Powershell: Exit Stage Left\",\"datePublished\":\"2009-09-01T13:36:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/\"},\"wordCount\":517,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"Event\",\"PowerShell\",\"Profile\",\"Register-EngineEvent\",\"ScriptBlock\",\"Scripting\"],\"articleSection\":[\"CommandLine\",\"PowerShell v2.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/\",\"name\":\"Powershell: Exit Stage Left &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2009-09-01T13:36:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/346\\\/powershell-exit-stage-left\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"CommandLine\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/commandline\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Powershell: Exit Stage Left\"}]},{\"@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":"Powershell: Exit Stage Left &#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\/scripting\/346\/powershell-exit-stage-left\/","og_locale":"en_US","og_type":"article","og_title":"Powershell: Exit Stage Left &#8226; The Lonely Administrator","og_description":"While reviewing and revising the manuscript for Windows PowerShell v2.0: TFM 3rd ed. I had the opportunity to revisit our chapter on working with events in PowerShell. An event in Windows is when something happens like a mouse-click, a process being created or window resized. In PowerShell you can easily watch for an event of interest and then do something when it happens or fires. This is referred to as an event subscription.  PowerShell v2.0 has a few event related cmdlets you can use for creating an event subscription: Register-WMIEvent, Register-ObjectEvent and Register-EngineEvent. Today I want to show you something I think you might find helpful using the last cmdlet in the list.","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/","og_site_name":"The Lonely Administrator","article_published_time":"2009-09-01T13:36:00+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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Powershell: Exit Stage Left","datePublished":"2009-09-01T13:36:00+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/"},"wordCount":517,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["Event","PowerShell","Profile","Register-EngineEvent","ScriptBlock","Scripting"],"articleSection":["CommandLine","PowerShell v2.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/","name":"Powershell: Exit Stage Left &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2009-09-01T13:36:00+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/346\/powershell-exit-stage-left\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"CommandLine","item":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},{"@type":"ListItem","position":2,"name":"Powershell: Exit Stage Left"}]},{"@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":622,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/622\/powershell-for-developers\/","url_meta":{"origin":346,"position":0},"title":"PowerShell for Developers","author":"Jeffery Hicks","date":"April 12, 2010","format":false,"excerpt":"I'll be presenting before the CNY Developers Group on May 5, 2010. The topic of my talk will be an introduction to Windows\u00a0 PowerShell 2.0 aimed at a developer audience. I'll talk about PowerShell as a management shell, its architecture, some scripting basics and how PowerShell relates to .NET and\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":582,"url":"https:\/\/jdhitsolutions.com\/blog\/writing\/582\/powershell-in-the-enterprise\/","url_meta":{"origin":346,"position":1},"title":"PowerShell in the Enterprise","author":"Jeffery Hicks","date":"March 4, 2010","format":false,"excerpt":"A new whitepaper I wrote for Quest Software has finally made it's public appearance: PowerShell in the Enterprise: Best Practices and Recommendations. The paper discusses some best practices for using PowerShell in an enterprise environment. Essentially, getting the most from your PowerShell \"investment\", especially when you might have multiple PowerShell-based\u2026","rel":"","context":"In &quot;Best Practices&quot;","block_context":{"text":"Best Practices","link":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":748,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/748\/get-your-free-scripting-toolkit\/","url_meta":{"origin":346,"position":2},"title":"Get Your Free Scripting Toolkit","author":"Jeffery Hicks","date":"July 29, 2010","format":false,"excerpt":"If you were at this year's TechEd event in New Orleans, I hoped you dropped by the SAPIEN Technologies booth and picked up your free Scripting Toolkit. What's that you say? Check it out on the SAPIEN blog and then download your free copy.","rel":"","context":"In &quot;Books&quot;","block_context":{"text":"Books","link":"https:\/\/jdhitsolutions.com\/blog\/category\/books\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":343,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/343\/revising-windows-powershell-tfm-3rd\/","url_meta":{"origin":346,"position":3},"title":"Revising Windows PowerShell: TFM 3rd","author":"Jeffery Hicks","date":"August 21, 2009","format":false,"excerpt":"I know there was some concern related to my departure from SAPIEN about the status of the Windows PowerShell: TFM book. You\u2019ll be happy to know that Don Jones and I are both involved now in the final revisions.\u00a0 SAPIEN is very committed to this project and supporting the PowerShell\u2026","rel":"","context":"In &quot;Books&quot;","block_context":{"text":"Books","link":"https:\/\/jdhitsolutions.com\/blog\/category\/books\/"},"img":{"alt_text":"header_sapien_press","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/08\/header_sapien_press.gif?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2044,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2044\/maximizing-the-powershell-console-title-bar\/","url_meta":{"origin":346,"position":4},"title":"Maximizing the PowerShell Console Title Bar","author":"Jeffery Hicks","date":"January 31, 2012","format":false,"excerpt":"A few days ago Boe Prox posted some very nifty PowerShell modules for using the title bar as a ticker for RSS feeds like the weather. I thought this was an awesome idea and an easy way to take advantage of what would otherwise be unused screen space. I was\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/01\/console-title-sysstat-300x85.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1171,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1171\/powershell-deep-dive-formatting-and-extensions\/","url_meta":{"origin":346,"position":5},"title":"PowerShell Deep Dive Formatting and Extensions","author":"Jeffery Hicks","date":"February 25, 2011","format":false,"excerpt":"I just found out I will be presenting at the PowerShell Deep Dive April 18-19 that is part of TEC 2011. This promises to be THE PowerShell event everyone has been waiting for. I'll be presenting on format and type extensions. Mastering Format and Type Extensions Windows PowerShell is designed\u2026","rel":"","context":"In &quot;Conferences&quot;","block_context":{"text":"Conferences","link":"https:\/\/jdhitsolutions.com\/blog\/category\/conferences\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/346","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=346"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}