Tuesday, November 8, 2011

Close multiple “Not responding” Processes or Applications using “PowerShell”

 

Hi,

Yesterday I was working on Powerpoint, Word, and Excel simultaneously  and the files which i have opened in these programs was very heavy in size. so after few hours of continuous working on that these application got “Hanged” and they were "stopped Responding” .

Then I open “Task Manager”, select the each process and Kill them manually.

at that point I think, there should be some “PowerShell Way” to achieve the same task using script.

Yes there, Let me share it with you.

The cmdlets which we use to accomplish are: Get-Process , Where-Object, Get-Member (alias is gm)

Let’s Start :

Open PowerShell Console

type Get-Process and (|) Pipe to another cmdlet Get-Member or you can use the alias GM ,

Capture 0

this command shows your the all properties  and Methods used by Processes.

We are Interested the only two member properties, one is the Responding Property which in boolean (either True or False) and another one is Kill() which in Method to kill the process

Capture-0

Capture-5

lets begin.

for example :

My Notepad is stopped working and lets close it using PowerShell

Capture

type the command

Get-Process   | Where-Object { $_.responding -eq $false}

get-process will get the list of all running process and then piped to another command, the Where-Object command select only those services whose Responding status is False or we can say Not-responding

It found Notepad is not responding

Capture-2

but i want to put the above command in to variable, so if there is more then one process which are not responding they all get close in a single command.

$notres = Get-Process   | Where-Object { $_.responding -eq $false}

Capture-3

I used $notres variable and it stores our Get-Process | Where-Object { $_.responding -eq $false} command.

Now execute the Kill() Method and you will see that all “Not Responding” processes are closes now :)

$notres.Kill()

   Capture-4   

 

That’s All

 

Thanks for viewing

 

Aman Dhally

www.amandhally.net

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.