O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

21.4. Executing Processes and Commands

You might remember our little problem from Chapter 14: with all the built-in process-related cmdlets that PowerShell has, getting a reference to the process you just started is still quite hard. We had two solutions: look for the process using its expected window title or process name shortly after you start it or use a piece of .NET code that starts the process like this:

PS C:\> $notepad = [Diagnostics.Process]::Start("notepad.exe")
PS C:\> $notepad

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     51       3     1860       7188    42     0.13   2816 notepad

The preceding solution works fine with the minor inconvenience that it is hard to pass command-line parameters ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required