Powershell 启动进程列表,然后终止它们

Powershell 启动进程列表,然后终止它们,powershell,process,Powershell,Process,使用powershell如何启动一些正在运行的进程,然后在稍后杀死它们 我使用以下方法启动流程: ps Start-Process "notepad.exe" 创建名为run.ps1的文件,其中包含以下内容: $apps = New-Object System.Collections.Generic.List[Object] $app = Start-Process "notepad.exe" -passthru $apps.Add($app) $app = Start-Process

使用powershell如何启动一些正在运行的进程,然后在稍后杀死它们

我使用以下方法启动流程:

ps
Start-Process "notepad.exe"

创建名为run.ps1的文件,其中包含以下内容:

$apps = New-Object System.Collections.Generic.List[Object]

$app = Start-Process "notepad.exe"  -passthru
$apps.Add($app)

$app = Start-Process "notepad.exe"  -passthru
$apps.Add($app)

Write-Host "Press any key to terminate ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

#Kill the running processes
foreach ($app in $apps) 
{
    Write-Host "Killing" ($app.Id -as [string])
    Stop-Process $app.Id
}
现在,您可以使用以下命令执行它:

powershell.exe -executionpolicy remotesigned -File  ./test.ps1