開始プロセスのメモ帳 | 停止プロセス
私が何をすべきかをほとんどすべて知っています。
Start-Process はプロセスを開始するだけです。開始された後にそのプロセスを参照する方法は提供しません。それを行う別の方法は次のとおりです。
# // Declare an array to hold Process IDs
$aProcessIDs = @()
# // Create a Wscript.Shell object to use for running processes
$oWshShell = New-Object -ComObject Wscript.Shell
# // Start 10 instances of notepad
for ($i=1;$i -le 10;$i++)
{
# // Run notepad.exe
$oProcess = $oWshShell.Exec('notepad.exe')
# // Add the ProcessID of the running process to the array
$aProcessIDs += $oProcess.ProcessID
}
# /// Wait 10 seconds
Start-Sleep -s 10
# // Terminate all processes
foreach ($iProcessID in $aProcessIDs)
{
Stop-Process -Id $iProcessID
}