Run and time a script or command in the background

Running for example release scripts for releasing software, can have a large overhead if you print a lot of info in the console. At the same time you might want to time the relase to see how fast it us. Easy enough you run your command/ps1 file in the background using the start-job commandlet.

This script uses start-job together with Register-ObjectEvent to be able to time a job running in the background, for example:

PS >.\RunACommandInTheBackground.ps1 .\MakeRelease.ps1 https://svnserver:port/svn/OurProduct/trunk 613
Starting .\MakeRelease.ps1 https://svnserver:port/svn/OurProduct/trunk 613 as Job #1...
PS > Job #1 is finished...
Job Started:  10/29/2010 07:51:34
Job Stopped:  10/29/2010 07:54:39
Time Elapsed: 00:03:05.3862306
PS > Get-Job
PS >

The script  runs a command or powershell script with any number of parameters in the background. The script creates a job runs it and shows start, stop and elapsed time when the job is terminated. The job is also removed from the Job list on termination.

 

Anonymous