My Technical Notes

Sunday, 20 December 2015

PowerShell: Start script and then kill it

Given a script, `MyScript.ps1`, to start it we use the `Start-Process` command with the `-PassThru` option which will return a variable representing the process:


$process = Start-Process powershell.exe '.\MyScript.ps1' -PassThru

Thereafter, we can kill it using:


$process.Kill();
or

Stop-Process -Id $process.Id -Force

No comments: