I need to call an external application (i.e. & 'Notepad' ) and then get the process ID of the called application.
Get-Process Notepad = will return all Notepad processes
I want to do something like:
$objApp = & 'c:\Notepad.exe' WHILE (get-process -ID $objApp.id | select -property Responding) { Start-Sleep -s 10 Echo "STILL WAITING" } Echo "Done!!"
To find the PID of a process, type Get-Process . Indicates that the UserName value of the Process object is returned with results of the command. Specifies one or more process objects. Enter a variable that contains the objects, or type a command or expression that gets the objects.
Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column.
$PID is an automatic variable and contains the process identifier of the process hosting the current PowerShell session. With the -id option of get-process , it is possible to query some data about the current powershell process: get-process -id $PID | format-table startTime, path, workingSet.
Use Start-Process
with the -PassThru
argument like this:
$app = Start-Process notepad -passthru Wait-Process $app.Id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With