{"id":50773,"date":"2010-04-03T00:01:00","date_gmt":"2010-04-03T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/04\/03\/hey-scripting-guy-weekend-scripter-the-scripting-wife-learns-how-to-start-and-stop-processes\/"},"modified":"2010-04-03T00:01:00","modified_gmt":"2010-04-03T00:01:00","slug":"hey-scripting-guy-weekend-scripter-the-scripting-wife-learns-how-to-start-and-stop-processes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-weekend-scripter-the-scripting-wife-learns-how-to-start-and-stop-processes\/","title":{"rendered":"Hey, Scripting Guy! Weekend Scripter: The Scripting Wife Learns How to Start and Stop Processes"},"content":{"rendered":"<p><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/p>\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. The <a href=\"http:\/\/en.wikipedia.org\/wiki\/Callery_Pear\"><font face=\"Segoe\">Bradford pear trees<\/font><\/a> are in bloom in Charlotte, North Carolina, in the United States. The small, delicate, white blossoms that grace the twisted shrub-like trees drape like pearls around the neck of a stately dowager. For a short two-week period, the Deep South is clothed in color, bringing out a hidden charm that seems to pervade the very social fabric of the town.<\/p>\n<p class=\"MsoNormal\">The cool temperatures, clear blue skies, and blooming trees conspire to draw me out of doors. The great thing about wireless networking is I can sit in a lawn chair on the deck in the back yard, and enjoy the beginnings of spring while also getting work done. To celebrate the change in seasons, I made a pot of green tea with jasmine. <\/p>\n<p class=\"MsoNormal\">I was working on a Windows PowerShell script for a future Hey, Scripting Guy! Blog post, when the Scripting Wife showed up carrying her laptop. <\/p>\n<p class=\"MsoNormal\">&ldquo;Hey, Scripting Guy! I have a question,&rdquo; she said as she pulled up a chair. <\/p>\n<p class=\"MsoNormal\">&ldquo;Yes,&rdquo; I replied.<\/p>\n<p class=\"MsoNormal\">&ldquo;I still don&rsquo;t understand Windows PowerShell. What is it good for?&rdquo; she queried.<\/p>\n<p class=\"MsoNormal\">&ldquo;Suppose you are a network administrator and you&hellip;&rdquo;<\/p>\n<p class=\"MsoNormal\">&ldquo;But I am not a network administrator,&rdquo; she hastily interrupted.<\/p>\n<p class=\"MsoNormal\">&ldquo;Yeah, that is right,&rdquo; I admitted, trying another tack. &ldquo;Suppose you have several copies of a program open, and you want to close all of them at the same time. What would you do,&rdquo; I asked.<\/p>\n<p class=\"MsoNormal\">&ldquo;Well, I would go to each program, and click the &lsquo;X&rsquo; in the upper right hand corner,&rdquo; she said.<\/p>\n<p class=\"MsoNormal\">&ldquo;Exactly. If you had 10 programs open, that would be 10 clicks. And for each one, you would have to wait until the program came to the foreground so that you could click the &lsquo;x&rsquo;,&rdquo; I said.<\/p>\n<p class=\"MsoNormal\">&ldquo;Well, I guess I could also use Task Manager to kill the processes,&rdquo; she added.<\/p>\n<p class=\"MsoNormal\">&ldquo;That is true, but unfortunately, as you can see here, Task Manager does not allow you to select several programs and kill the processes with one click,&rdquo; I added while opening Task Manager (as shown in the following image).<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of processes in Task Manager\" alt=\"Image of processes in Task Manager\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/april\/hey0403\/wes-04-03-10-01.jpg\" width=\"600\" height=\"428\"><\/p>\n<p class=\"Fig-Graphic\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">&ldquo;So you are still stuck with selecting the process, and then navigating down to the <b>End Process<\/b> button to kill the process. So there is still a lot of extra work. Using the <b>Stop-Process<\/b> cmdlet, you can stop all of the processes at once. Here, let me show you,&rdquo; I said pausing for things to sink in. She made the requisite listening noises, so I continued. <\/p>\n<p class=\"MsoNormal\">&ldquo;In your Windows PowerShell console, type <b><span>Stop-P<\/span> <\/b>and press TAB. Windows PowerShell will complete the <b>Stop-Process<\/b> cmdlet name for you. Now, you need to tell Windows PowerShell that you are going to give it a process name. Type <b>&ndash;n<\/b> and press TAB to complete the <b><span>&ndash;name<\/span><\/b> parameter. Now all you need to do is supply the name of the process to stop. In this example, use <span>notepad<\/span>. The command, my dear Scripting Wife, is therefore <span><strong>Stop-Process &ndash;name notepad<\/strong><\/span>. You can see it in your Windows PowerShell console,&rdquo; I said (the following image shows the command).<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of stopping Notepad process\" alt=\"Image of stopping Notepad process\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/april\/hey0403\/wes-04-03-10-02.jpg\" width=\"485\" height=\"263\"><\/p>\n<p class=\"Fig-Graphic\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">&ldquo;Did it work? I don&rsquo;t see anything,&rdquo; she commented in a rather confused voice.<\/p>\n<p class=\"MsoNormal\">&ldquo;Are all the copies of Notepad gone? Let&rsquo;s use Task Manager to see,&rdquo; I suggested. &ldquo;Yep, they are all gone.&rdquo; (See the following image as proof.)<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of all Notepad processes gone from Task Manager\" alt=\"Image of all Notepad processes gone from Task Manager\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/april\/hey0403\/wes-04-03-10-03.jpg\" width=\"600\" height=\"428\"><\/p>\n<p class=\"Fig-Graphic\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">&ldquo;As you can see using the <b>Stop-Process<\/b> cmdlet to stop multiple copies of the same process can be extremely efficient. But you can also use it to stop processes that are not from the same program,&rdquo; I said. <\/p>\n<p class=\"MsoNormal\">&ldquo;Now, Scripting Wife, if you will type <b><span>Start-P<\/span><\/b> and press TAB, tab completion will fill out the rest of the <b>Start-Process<\/b> cmdlet name. Use the <b>Start-Process<\/b> cmdlet to start an instance of Notepad. Press the up arrow and change <b><span>notepad<\/span><\/b> to <b><span>calc<\/span><\/b>. Your commands thus far are <b>Start-Process Notepad<\/b> and <b>Start-Process Calc<\/b>,&rdquo; I said.<\/p>\n<p class=\"MsoNormal\">&ldquo;Do you see Notepad and Calculator running?&rdquo; I asked.<\/p>\n<p class=\"MsoNormal\">&ldquo;Yes,&rdquo; she replied. <\/p>\n<p class=\"MsoNormal\">&ldquo;Cool, now we will <i>stop<\/i> both Calculator and Notepad in a single command. Type <b><span>Stop-p<\/span><\/b> and press TAB,&rdquo; I said.<\/p>\n<p class=\"MsoNormal\">&ldquo;Ok, now what?&rdquo; she asked.<\/p>\n<p class=\"MsoNormal\">&ldquo;After you have typed <b><span>Stop-p<\/span><\/b> and pressed TAB, type <b><span>&ndash;n<\/span><\/b> and press TAB. Tab completion will complete the <b>&ndash;name<\/b> parameter. How are you doing?&rdquo; I inquired.<\/p>\n<p class=\"MsoNormal\">&ldquo;I am a simple user, not simple,&rdquo; she replied acidly. &ldquo;Just get on with it. I don&rsquo;t have all day.&rdquo;<\/p>\n<p class=\"MsoNormal\">&ldquo;Okay, after the <b>&ndash;name<\/b> parameter, type <b><span>notepad, calc<\/span><\/b>. Press ENTER when you are finished,&rdquo; I said. <\/p>\n<p class=\"MsoNormal\">&ldquo;Did I do it right,&rdquo; she asked, turning her laptop around so I could see it. The following image shows what I saw on her laptop.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of stopping Notepad and Calculator processes\" alt=\"Image of stopping Notepad and Calculator processes\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/april\/hey0403\/wes-04-03-10-04.jpg\" width=\"600\" height=\"273\"><\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">&ldquo;Indeed you did. Now why don&rsquo;t you go play with that, and see what else you can discover about those two cmdlets? I need to get back to work on this script I am working on for next week,&rdquo; I said. <\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">Weekend Scripter will continue tomorrow as the Scripting Wife attempts to&hellip;if you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\"><font face=\"Segoe\">Twitter<\/font><\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/p>\n<p><\/span><\/b><\/p>\n<p><b><span><\/span><\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Microsoft Scripting Guy Ed Wilson here. The Bradford pear trees are in bloom in Charlotte, North Carolina, in the United States. The small, delicate, white blossoms that grace the twisted shrub-like trees drape like pearls around the neck of a stately dowager. For a short two-week period, the Deep South is clothed in color, [&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":[51,3,74,61,45],"class_list":["post-50773","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-wife","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Microsoft Scripting Guy Ed Wilson here. The Bradford pear trees are in bloom in Charlotte, North Carolina, in the United States. The small, delicate, white blossoms that grace the twisted shrub-like trees drape like pearls around the neck of a stately dowager. For a short two-week period, the Deep South is clothed in color, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/50773","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=50773"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/50773\/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=50773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=50773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=50773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}