Kace script verify two or more process are not running
Hello, i have created a online kscript that verifies if a process is running if so (on success)run something.
Now i want to add two or more processes to the same script. So the outcome will be all both or three processes are no running then on success run something.
However i tried adding two more verify a process is running to the same task. this has not worked as it looks like it will only continue if there is a success.
for example
process 1 = is running
Process 2 = is running
process 3 = is running.
The output is it checks process 1 and thats a fail as it is running, then it does not check process 2 or 3.
I tried adding different tasks so that it verifies each process, but the output im looking for is i only want something to run if all three processes are not running.
Any ideas on this?
thanks
2 Comments
[ + ] Show comments
Answers (1)
Please log in to answer
Posted by:
JasonEgg
7 years ago
Just do a launch program:
Dir:$(KACE_SYS_DIR)
File:Powershell.exe
Wait
executionpolicy bypass -file "$(KACE_DEPENDENCY_DIR)\ProcCheck.ps1"
Then save this as ProcCheck.ps1
$Output = 0
@(
"Word",
"Outlook",
"Excel"
) | Foreach-Object {
if (Get-Process $_ -ErrorAction SilentlyContinue)
{ Write-Output "$_ is running" }
else {
Write-Output "$_ is not running... Adding 1 to variable"
$Output++ }
}
Write-Host $Output
If (($Output) -eq 3) { Exit 0 } else { Exit 1 } - Desktop Jockey 7 years ago