开发者

Monitor hung instances of a powershell script

I´m writing a Powershell script to do a bunch of things and when finished it will be run as a sch开发者_如何学Goeduled task. For that reason I want to be able to check whether an older instance is still alive when I start running the script and kill the older one if it exists.

I was thinking I would use something like this:

$process = Get_Process | $name
$process.kill

But how to get the $name variable in a simple way?

Does anyone have a better suggestion? Best regards, Gísli


You can do this in windows scheduled task configuration. The settings depends on the OS you are using though.

EDIT: that is you can configure the task to be killed after a certain period of time (i.e. when your next one starts).


Why do you need to get the name? Get-Process returns high fidelity Process objects and you can operate on it directly.

To get a process of a particular name use $n = Get-Process notepad, say, and then do $n.kill() to kill it. If you do need to check the name again, do $n.Name. To see what properties and methods you can use, try $n | get-member

And make sure you read the manual: http://technet.microsoft.com/en-us/library/dd347630.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜