Home > View Post

PowerShell saves the day again

I recently posted the night PowerShell saved my music library. Well, he saved the day again last week.

Whilst carrying my laptop to the coffee shop at Microsoft's Offices in Reading, I accidentally managed to start 63 instances of the excellent TcpTrace application.

Yup, 63! No idea how.

Worst thing was, this application starts with a modal dialog so I couldn't even close group on the taskbar.

63 TcpTrace applications

And you can't multi-select in the task manager to kill multiple processes. You can't even do this in the fantastic Process Explorer.

Time for Powershell

Needless to say, PowerShell made mince-meat of 'em.

First of all, I used the get-process cmdlet to look at all the processes:

        get-process
        
Then I applied a filter to ensure I only had the tcpTrace processes

        get-process tcptrace
    
Easy. Now I just pipe this to a foreach and Kill() those processes.

        get-process tcptrace | foreach { $_.Kill() }

All gone! Hoorah.

Later I found the stop-process cmdlet which could have done this in one easy move:

    stop-process tcptrace

If you want to try this yourself, why not get Powershell to start 63 applications for you!

        for ($i=0; $i -ile 63; $i++) { c:\tools\tcptrace\tcptrace.exe }
        
Awesome.

Tags: Powershell

 
Josh Post By Josh Twist
6:44 AM
21 Sep 2007

» Next Post: Exporting VSTS load test results to a new database with PowerShell
« Previous Post: WPF for Line of Business Applications

Comments are closed for this post.

© 2005 - 2017 Josh Twist - All Rights Reserved.