{"id":109,"date":"2012-05-29T05:19:57","date_gmt":"2012-05-29T05:19:57","guid":{"rendered":"http:\/\/virtualworlduk.co.uk\/?p=109"},"modified":"2012-05-29T05:19:57","modified_gmt":"2012-05-29T05:19:57","slug":"checking-process-age-powershell-script","status":"publish","type":"post","link":"https:\/\/www.virtualworlduk.co.uk\/wordp\/checking-process-age-powershell-script\/","title":{"rendered":"Checking Process Age Powershell Script"},"content":{"rendered":"<p>The other day I stumbled across a powershell that is useful for checking out the age of a process running on a computer, unfortunately I cannot remember where I discovered it and therefore cannot give the relevant credit to the creator.<\/p>\n<p>I can here many of you say, about why is this Powershell script important and why have I placed it alongside the Veeam information?<\/p>\n<p>The answer to these questions is simple, the powershell script is especially useful when using Veeam Backup &amp; Replication and it was due to a situation I had when using Veeam Backup &amp; Replication that allowed me to look for the script in the first place.<\/p>\n<p>With Veeam Backup &amp; Replication v6, the Management Server communicates with the Proxies and starts up the VeeamAgent.exe process when backing up or replicating.\u00a0 Each task that is running, will create a process like this.\u00a0 In some circumstances, a Backup job may freeze even though other jobs are running through smoothly.\u00a0 I knew that if you kill the VeeamAgent.exe process, it would stop the backup job and allow you to restart it later&#8230; unfortunately I didn&#8217;t want to stop all VeeamAgent.exe processes on the proxy as that would kill the backup jobs that are working fine.\u00a0 If I knew the age of the VeeamAgent.exe processes and compare the start time with the start time of the virtual machine backup that has frozen&#8230; I would then be able to kill just that process and allow the other backup tasks to continue running.<\/p>\n<p>So here is the script:<\/p>\n<p dir=\"LTR\">[cmdletbinding()]<\/p>\n<p dir=\"LTR\">param(<\/p>\n<p dir=\"LTR\">$ComputerName=$env:COMPUTERNAME,<\/p>\n<p dir=\"LTR\">[parameter(Mandatory=$true)]<\/p>\n<p dir=\"LTR\">$ProcessName<\/p>\n<p dir=\"LTR\">)<\/p>\n<p dir=\"LTR\">$Processes = Get-WmiObject -Class Win32_Process -ComputerName $ComputerName -Filter &#8220;name=&#8217;$ProcessName'&#8221;<\/p>\n<p dir=\"LTR\">if($Processes) {<\/p>\n<p dir=\"LTR\">foreach ($process in $processes) {<\/p>\n<p dir=\"LTR\">$processid = $process.handle<\/p>\n<p dir=\"LTR\">$processcreationtime = $Process.Converttodatetime($Process.creationdate)<\/p>\n<p dir=\"LTR\">write-host &#8220;`nThe $ProcessName `($processid`) process creation time is $processcreationtime&#8221;<\/p>\n<p dir=\"LTR\">}<\/p>\n<p dir=\"LTR\">} else {<\/p>\n<p dir=\"LTR\">write-host &#8220;`nNo Process found with name $ProcessName&#8221;<\/p>\n<p dir=\"LTR\">}<\/p>\n<p>write-host &#8220;&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p>This script should be saved in a .ps1 file and stored somewhere on your network.\u00a0 To run the script, start up Powershell.\u00a0 I find it easier to browse to the folder where the script is located and execute the following command:<\/p>\n<p>.\/<em>nameofscript<\/em>.ps1 -ComputerName <em>NameofComputer<\/em> -ProcessName <em>NameofProcess<\/em><\/p>\n<p>So for in my environment, I actually have it available on the server that is the Veeam Proxy and therefore I start it as the following:<\/p>\n<p>.\/get-processage.ps1 -ProcessName VeeamAgent.exe<\/p>\n<p>&nbsp;<\/p>\n<p>At this poing you will see something similar to below:<\/p>\n<p><a href=\"http:\/\/virtualworlduk.co.uk\/wp-content\/uploads\/2012\/05\/process.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-110\" title=\"process\" src=\"http:\/\/virtualworlduk.co.uk\/wp-content\/uploads\/2012\/05\/process.jpg\" alt=\"\" width=\"589\" height=\"140\" \/><\/a><\/p>\n<p>At this point you compare the date and time of the processes with the start time of the frozen virtual machine backup, you can then\u00a0start up a command prompt on the Proxy server and run the following command to kill the process:<\/p>\n<p>taskkill \/PID\u00a0<em>processnumber<\/em> \/F<\/p>\n<p>The process number is the item in brackets and therefore in our example above, if we wanted to kill off the oldest process, we would run the following command:<\/p>\n<p>taskkill \/PID 948 \/F<\/p>\n<p>Seconds later the backup task will fail, at which point you can investigate the reason for it freezing and restart your backup task again.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I stumbled across a powershell that is useful for checking out the age of a process running on a computer, unfortunately I cannot remember where I discovered it and therefore cannot give the relevant credit to the creator. I can here many of you say, about why is this Powershell script important and why have I placed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-veeam"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":0,"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtualworlduk.co.uk\/wordp\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}