0

Is there anyway of using ps to get the pid of a powershell command which is already executing.

For e.g., say I've already executed the following command.

ls | ? { <where condition> } | % { <some operations> }

The goal is I open up another powershell window and type in something that allows me to wait for the above to complete.

Any ideas?

wp78de
  • 1,742
deostroll
  • 1,895

1 Answers1

1

allow me to wait for the above to complete.

In that command you are using a ForEach-Object (%).

The ForEach-Object has a default argument -Process that accepts the script block you are providing that is doing the processing for each item in the pipeline. But that commandlet also offers a -End {Scriptblock} argument that will be executed after all the pipeline input has been accepted and processed. You could use this -End block to send your notification somehow. Perhaps by writing a file or sending an email or whatever else you wanted to notify you.

ls | ? { <where condition> } | % { <some operations> } -End { #alert me!}
Zoredache
  • 20,438