Execute applications
Start process
It is possible start and run external applications from PowerShell. They are started via processes. It will be done with cmdlet Start-Process
. You have to give also a name of process or applications by the parameter FilePath
. In the following example the Firefox application has been started.
Start-Process -FilePath Firefox -ArgumentList www.jamk.fi
Close process
Of course, it would be nice to shut down a process/application which has been started. You will get a hook to the started process with a cmdlet Get-Process
and with a cmdlet Stop-Process
you can stop your process, which close your application.
In the following example the Firefox application has been started and closed immediately.
Start-Process -FilePath Firefox -ArgumentList www.jamk.fi
#get a hook to Firefox
$myapp = Get-Process Firefox
#close Firefox
Stop-Process $myapp
Let's tune a little bit the example. We will pause the script for ten seconds. And let's use the pipeline, not a variable.
#start Firefox
Start-Process -FilePath Firefox -ArgumentList www.jamk.fi
#pause script for 10 seconds
start-Sleep -Seconds 10
#pipeline to close Firefox
Get-Process Firefox | Stop-Process
Please, try it with your own computer.