Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Retrieve Last Token with PowerShell

$
0
0

Summary: Learn how to use Windows PowerShell to retrieve the last token and avoid retyping.

Hey, Scripting Guy! Question I used Get-Process to view a process I launched, and later I wanted to stop the process. How can I do this without
           doing a lot of typing or creating new variables?

Hey, Scripting Guy! Answer The $$ automatic variable contains the last token submitted, so do the following:

PS C:\> notepad

PS C:\> gps $$

Handles  NPM(K)    PM(K)    WS(K) VM(M)   CPU(s)   Id ProcessName

-------     ------    -----      -----   -----   ------        --         -----------

    116       9     1728       7396 ...67     0.06     4668             notepad

At this point, Notepad is still the last token, so you can view it directly, and use it to stop the process:

PS C:\> $$

notepad

PS C:\> Stop-Process -Name $$


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>