Killing a stalled process and leaving others running using PowerShell

Since I wrote my post “Using Loadrunner / Performance Center to kill a rogue process“, some colleagues have asked if I could kill a stalled process and leave others up and running. After some “Googling”, I have found that this is possible.

I modified some PowerShell scripts that I found online so that they do what we want. If you paste the code below into a PowerShell script called for example “KillStalledProcesses.ps1”, it will scan through all the processes on a machine and “kill” any that are not responding.

I’ve tested it using SysInternals “Process Explorer” which allows you to “suspend” a running process like in the image below. I suspended the “notepad.exe” process and tested the PowerShell code.

The code correctly identified the suspended process and “killed” it.

(When I tested this with two other running “notepad” processes, it left the two other processes running.)

My thoughts are that we could add the PowerShell script into the “Extra Files” portion of a LoadRunner or Performance Center script and call it on error using the system (command); function described in the initial blog post. This would kill for example a rogue Citrix or SAPGUI client and leave others running during a performance test.

 


[CmdletBinding()]     

( [string[]]$ComputerName = $env:ComputerName)           

($Computer in $ComputerName)

if(!(Test-Connection -ComputerName $Computer -Count 1 -quiet))

Write-Host "$Computer : OFFLINE"           

Continue           

try {

$Processes = Get-Process -ComputerName $Computer -EA Stop

$nProcesses = @($Processes | ? { $_.Responding -eq $false })

catch {

Write-Error "Failed to query processes. $_"

if($nProcesses)

foreach($nProcess in $nProcesses)

$nProcess | select Name, id, MainWindowTitle, Responding

Write-host "Attempting to kill stalled process"

if ($nProcess.Id -ne $PID)

Stop-Process $nProcess.Id}

else

Write-host "No non-responding processes found"

HPE software and Micro Focus merger

In September many people were surprised at the news that HPE was set to spin-off their software business including the former HP Operations Management products and former Mercury products.

I wrote a brief article decribing my thoughts about this at the time.

Since this announcement, more information has been released by HPE describing their reasoning behind this proposed change to their business as well as what it means for their customers. The Vivit user group in Chicago recently held a webinar hosted by Mihai Grigorescu which allowed HPE to describe the proposed changes. Tony Sumpster and Genefa Murphy from HPE then took questions from Vivit members. If you’re a current HPE Software customer I’d heartily recommend watching this webinar.

tony_sumpster_hpe genefa_murphy_hpe
 Tony Sumpster
Senior Vice President
IT Operations Management
Hewlett Packard Enterprise
Genefa Murphy
Vice PresidentProduct & Program Marketing
Application Delivery Management
Hewlett Packard Enterprise

The webinar is available on the Vivit website at this URL:
(Free Vivit membership required)
http://www.vivit-worldwide.org/members/group_content_view.asp?group=80108&id=620706

Alternatively, you can view the webinar by clicking the link below
(Bright Talk membership required)
https://www.brighttalk.com/webcast/9649/229733

Batch file to delete files older than x days from folders in Windows

I’ve been working for a client over recent months and part of my resposibility has been to look after a number of servers used for performance testing. Occasionally drives fill up on the server farm causing outages and obvious interruptions to testing.

It would be a near full-time job to manage all these servers, so to reduce the chance of temporary files from filling up drives and causing problems, I looked into creating a scheduled task to delete old temporary files. Since my server estate is varied, I didnt want to use PowerShell so I opted for an old “DOS” command, FORFILES.

This seems to have done the trick for me:
forfiles /s /m *.* /d -7 /c "cmd /c del @path"

(This command deletes all files that are more than 7 days old from the folder in which it runs.)

Update – To remove folders as well:
forfiles /S /D -7 /C "cmd /c IF @isdir == TRUE RMDIR @path /S /Q"

(This command deletes all folders that are more than 7 days old from the folder in which it runs. – Run it after deleting the files with the command above.)