{"id":73651,"date":"2015-08-30T11:59:00","date_gmt":"2015-08-30T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/08\/30\/powertip-retrieve-last-token-with-powershell\/"},"modified":"2019-02-18T09:35:25","modified_gmt":"2019-02-18T16:35:25","slug":"powertip-retrieve-last-token-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-retrieve-last-token-with-powershell\/","title":{"rendered":"PowerTip: Retrieve Last Token with PowerShell"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Learn how to use Windows PowerShell to retrieve the last token and avoid retyping.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;I used&nbsp;<b>Get-Process<\/b>&nbsp;to view a process I launched, and later I wanted to stop the process. How can I do this without <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;doing a lot of typing or creating new variables?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;The&nbsp;<b>$$&nbsp;<\/b>automatic variable contains the last token submitted, so do the following:<\/p>\n<p style=\"margin-left:90px\">PS C:\\&gt; notepad<\/p>\n<p style=\"margin-left:90px\">PS C:\\&gt; gps $$<\/p>\n<p style=\"margin-left:90px\">Handles&nbsp; NPM(K)&nbsp;&nbsp;&nbsp; PM(K) &nbsp; &nbsp;WS(K) VM(M)&nbsp;&nbsp; CPU(s) &nbsp; Id ProcessName<\/p>\n<p style=\"margin-left:90px\">&#8212;&#8212;- &nbsp; &nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211; &nbsp; &#8212;&#8211;&nbsp;&nbsp; &#8212;&#8212; &nbsp; &nbsp; &nbsp; &nbsp;&#8212; &nbsp; &nbsp; &nbsp; &nbsp; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"margin-left:90px\">&nbsp;&nbsp;&nbsp; 116&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9&nbsp;&nbsp;&nbsp;&nbsp; 1728&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7396 &#8230;67&nbsp;&nbsp;&nbsp;&nbsp; 0.06 &nbsp; &nbsp; 4668 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; notepad<\/p>\n<p style=\"margin-left:60px\">At this point, Notepad is still the last token, so you can view it directly, and use it to stop the process:<\/p>\n<p style=\"margin-left:90px\">PS C:\\&gt; $$<\/p>\n<p style=\"margin-left:90px\">notepad<\/p>\n<p style=\"margin-left:90px\">PS C:\\&gt; Stop-Process -Name $$<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Windows PowerShell to retrieve the last token and avoid retyping. &nbsp;I used&nbsp;Get-Process&nbsp;to view a process I launched, and later I wanted to stop the process. How can I do this without &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;doing a lot of typing or creating new variables? &nbsp;The&nbsp;$$&nbsp;automatic variable contains the last [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[612,51,356,3,45],"class_list":["post-73651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-automatic-variables","tag-getting-started","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell to retrieve the last token and avoid retyping. &nbsp;I used&nbsp;Get-Process&nbsp;to view a process I launched, and later I wanted to stop the process. How can I do this without &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;doing a lot of typing or creating new variables? &nbsp;The&nbsp;$$&nbsp;automatic variable contains the last [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/73651","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=73651"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/73651\/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=73651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=73651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=73651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}