PowerShell to identify running processes
Posted: 2021-Jul-25, 10:02 am
21 Jul 2012 21:08
anjaliingale
Hi,
I am preety new to powershell scripting i need help.
I want to write script which search that which processes are running from the taskmanager and if the process are not running then send mail.
There are 4 processes so i want to check this in one program and i have to use config file to generalise the program
Please help to resovle this.
Till now i tried
----------------------------
#11 Sep 2012 15:09
Misterd
The Powershell way to lookup processes is by using Get-Process
If you want to look up the path of each running process.
anjaliingale
Hi,
I am preety new to powershell scripting i need help.
I want to write script which search that which processes are running from the taskmanager and if the process are not running then send mail.
There are 4 processes so i want to check this in one program and i have to use config file to generalise the program
Please help to resovle this.
Till now i tried
Code: Select all
set process_1 = "D:\test\abc.exe " -AL -UN="xxxxxxx" -PW="xxxxxxx" -OLEAPI
set process_2 = D:\auto\auto.exe
set process_3 = "D:\abc.exe " -AL -UN="xxxxxxx" -PW="xxxxxxxx." -WFSRVR ODBC
set process_4 = D:\copy.exe
WMIC /OUTPUT:C:\ProcessList.log path win32_process where name="abc.exe"
Type ProcessList.log > found.log
FOR /F %%A IN (found.log)
Do
(
set var1 = %%A
If /I var1 NEQ process_1
(
echo abc process is not running properly....
mailto
)
Else (
echo Autoarchive Broker is running....
)
)
goto end
:end
#11 Sep 2012 15:09
Misterd
The Powershell way to lookup processes is by using Get-Process
Code: Select all
$ProcessName="notepad"
Get-Process $ProcessName -ErrorAction SilentlyContinue > $Nul
If (!($?)){
Write-host "$ProcessName is NOT running"
} else {
Write-host "$ProcessName is running"
}
Code: Select all
$AllProcesses=Get-Process
foreach ($OneProcess in $AllProcesses) {
echo $OneProcess.path
}