IzzyTwinkly
asked on
selecting "A" or "B" in process using Powershell
Hi guys,
I am trying to write my first powershell script.
using powersehll, I want to delete all currently running processesAs and ProcessBs.
I wrote the following code, but it seems that it doesn't end anything.
how can i make this work? (There can be multiple running As and multiple running Bs)
function Kill-RunningProcess(){
$processesA = @(Get-Process sqlServr -ErrorAction SilentlyContinue)
$processesB = @(Get-Process winword -ErrorAction SilentlyContinue )
$array=@($processesA, $processesB)
if($array){
foreach($process in $processes){
$process.Kill()
}
}
}
I am trying to write my first powershell script.
using powersehll, I want to delete all currently running processesAs and ProcessBs.
I wrote the following code, but it seems that it doesn't end anything.
how can i make this work? (There can be multiple running As and multiple running Bs)
function Kill-RunningProcess(){
$processesA = @(Get-Process sqlServr -ErrorAction SilentlyContinue)
$processesB = @(Get-Process winword -ErrorAction SilentlyContinue )
$array=@($processesA, $processesB)
if($array){
foreach($process in $processes){
$process.Kill()
}
}
}
Get-Process accepts an array for process names to retrieve, so you can do that easily in a single line:
Get-Process -Name sqlServr, winword | Stop-Process
Or like this:Get-Process -Name sqlServr, winword | ForEach-Object {$_.Kill()}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Qlemo,
Your answer is very simple and clear. Thanks you!
Thanks to oBdA as well!
Your answer is very simple and clear. Thanks you!
Thanks to oBdA as well!
Open in new window
or simply
Open in new window