Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

powershell script to find a process is running or not

$
0
0

Hi Friends, I am new to this forum.  I have a small requirement.

I want to do the following:

 

1. I want to check a process and stop it gracefully 

2. If the process does not stop gracefully after 5 mins then I want to kill that process

I did try but I don't know how to check whether the process has stopped gracefully or not.

$timeout = new-timespan -Minutes 1

$sw = [diagnostics.stopwatch]::StartNew()

while ($sw.elapsed -lt $timeout)

{

if ( get-service E:\java\stop -user somebody -password "nobody")

{

return 

}

start-sleep -seconds 5

}

Get-Process nco_p_* | ForEach-Object { $_.Kill() }

E:\java\start -user somebody -password "nobody"

 

Can you help me how to do this?

 

Thanks,


Viewing all articles
Browse latest Browse all 8583

Trending Articles