PowerShell to identify running processes

Microsoft Windows
Post Reply
User avatar
Posts: 336
Joined: 2021-Jul-12, 1:37 pm

PowerShell to identify running processes

Post by MigrationUser »

21 Jul 2012 21:08


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)
     set var1 = %%A
     If /I var1 NEQ process_1
     echo abc process is not running properly....

Else (
     echo Autoarchive Broker is running....
goto end


#11 Sep 2012 15:09

The Powershell way to lookup processes is by using Get-Process

Code: Select all

Get-Process $ProcessName -ErrorAction SilentlyContinue > $Nul

If (!($?)){
    Write-host "$ProcessName is NOT running"
} else {
    Write-host "$ProcessName is running"
If you want to look up the path of each running process.

Code: Select all

foreach ($OneProcess in $AllProcesses) {
	echo $OneProcess.path
Post Reply