Hi,
I wrote a script which will kill a process on multiple servers which age is more than 15mins. Below is the script:
[pre]
$ServerList = Get-Content Servers.txt
#mail configuration
$FromAddress = “XXXXX”
$ToAddress = “XXXXX”
$SendingServer = “XXXXX”
foreach( $Server in $ServerList)
{
$startTimeLimit = (get-date) - (new-timespan -minutes 15)
$processes_to_kill = get-process | where {($.Name -eq “winword”) -and
($.StartTime -lt (get-date).addminutes(15)) }
if ($processes_to_kill -ne $null)
{
$processes_to_kill | foreach { $_.Kill() }
$MessageSubject = “winword.exe process found running over 15 min’s & killed on ${server}”
$MessageBody =“${server} - winword.exe process found running over 15 min’s & killed”
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
#Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
}
}
[/pre]
But, the above script is not killing it. Can someone help me on this, If I am missing something. It would be great, If I can get the PID of the process aswell after killing.
Thanks,
Kalyan