如何获取 IIS AppPool 工作进程 ID [英] How to get IIS AppPool Worker Process ID

查看:23
本文介绍了如何获取 IIS AppPool 工作进程 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PowerShell 脚本,它会在我们的监控服务检测到网站关闭时自动运行.它应该停止AppPool(使用Stop-WebAppPool -name $AppPool;),等到它真的停止然后重新启动它.

I have a PowerShell script that is run automatically when our monitoring service detects that a website is down. It is supposed to stop the AppPool (using Stop-WebAppPool -name $AppPool;), wait until it is really stopped and then restart it.

有时进程实际上并没有停止,表现为错误

Sometimes it the process does not actually stop, manifested by the error

Cannot Start Application Pool:  
The service cannot accept control messages at this time.
(Exception from HRESULT: 0x80070425)"

当您再次尝试启动时.

如果停止所需的时间超过特定秒数(我将在对几次停止进行计时后选择该时间量以查看通常需要多长时间),我只想终止该进程.

If it takes longer than a certain number of seconds to stop (I will chose that amount of time after I have timed several stops to see how long it usually takes), I want to just kill the process.

我知道我可以通过执行 dir IIS:AppPoolsMyAppPoolWorkerProcesses,

I know that I can get the list of processes used by workers in the AppPool by doing dir IIS:AppPoolsMyAppPoolWorkerProcesses,

Process ID  State      Handles  Start Time
----------  -----      -------  ----------
7124        Running

但我不知道如何实际捕获进程 ID 以便我可以杀死它.

but I can't figure out how to actually capture the process id so I can kill it.

推荐答案

如果 Process ID 确实是要杀死的进程的 ID,您可以:

In case that Process ID is really the id of process to kill, you can:

$id = dir IIS:AppPoolsMyAppPoolWorkerProcesses | Select-Object -expand processId
Stop-Process -id $id

dir IIS:AppPoolsMyAppPoolWorkerProcesses | % { Stop-Process -id $_.processId }

这篇关于如何获取 IIS AppPool 工作进程 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆