How to do it...

If you listed out the commands in the previous recipe, scroll up to find what cmdlets might help you with this recipe.

  1. At the prompt, type in the following to start Visual Studio Code.
PS> Start-Process code

Ensure that the status bar at the bottom is not blue. If it is blue, read the Getting Ready section of this recipe. Press Ctrl + Shift + E or click on Explorer icon on the left sidebar of VS Code. There should not be any directory open there.

  1. Open VS Code at the directory you created the hello-world script.
PS> Start-Process code -ArgumentList /home/ram/Documents/code/github/powershell/

Press Ctrl + Shift + E or click on Explorer icon on the left sidebar of VS Code. Do you see the directory open?

Now, let us stop the VS Code process.

  1. List out the processes running in the system and see if anything matches code.
PS> Get-Process | grep code
  1. If you want the PowerShell way of doing it, run the following command and note the name in the ProcessName column:
PS> Get-Process *code*
  1. PowerShell deals with objects; grep outputs text. Therefore, now that we know that the exact name of the process is code, we directly get details on the process.
PS> Get-Process code

That gives us a valid output.

  1. Stop all the code processes.
PS> Stop-Process code

That would not work; the cmdlet accepts a System.Diagnostics.Process object as input.

  1. Enclose Get-Process within parentheses and pass the input to Stop-Process.
PS> Stop-Process (Get-Process code)
  1. Now, see if there is a code process running any more.
PS> Get-Process code

The best way of stopping a process is using its ID.

  1. I am running dconf-editor on my PC right now, and would like to close it. You may choose any process to stop; play safe, though.
PS> Get-Process dconf-editor
PS> Stop-Process -Id 20608
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.51.241