powershell - 通过站点名称杀死IIS工作进程

标签 powershell iis

对于此问题,“站点名称” = IIS称为站点的名称。例如,输出为:

ls IIS:\Sites\ | select Name

给定具有这些站点名称的文本文件,我想遍历所有正在运行的w3wp.exe进程,然后终止(而不是回收,终止)所有与列表中的站点名称无关的w3wp.exe进程。 (我的列表不是ls IIS:\ Sites \ |选择Name btw的输出,这只是定义我们称为“站点名称”的示例。我的列表是应该在服务器上运行的站点名称的列表,手动创建)

我可以用杀死所有w3wp.exe
taskkill /IM w3wp.exe /F

但是我正在努力在IIS站点名称及其关联的工作进程之间建立连接,因此我可以根据站点名称杀死特定的IIS。我猜我需要去siteName> appPool> worker程序...但是我很难过。

最佳答案

$workerProcesses = Get-CimInstance Win32_Process -Filter "name='w3wp.exe'"
foreach ($workerProcess in $workerProcesses)
{
    $wpSiteName = $workerProcess.CommandLine.split(" ")[2].replace("`"","")
    $wpPID = $workerProcess.ProcessId

    if ($myListNotShownHere -notcontains $wpSiteName)
    {
        #taskkill /f /pid $wpPID   
    }
}

关于powershell - 通过站点名称杀死IIS工作进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24786874/

相关文章:

powershell - PowerShell 中的函数范围变量(使用高级方法)?

asp.net - 未调用 ClaimsAuthenticationManager

asp.net - 内部服务器错误 500.24

powershell - 如何使用 WMI 和 Powershell 保存对 Windows 组的更改

powershell - azure函数powershell从存储队列读取并写入存储表

windows - 如何在 PowerShell 上安装 git(在 PowerShell 上使用 bash)?

powershell - 将多个值传递给单个 PowerShell 脚本参数

php - "Object named IIS_IUSRS could not be found"将用户添加到 PHP session 目录 iis 8

multithreading - IIS 工作线程问题

asp.net - NuGet: 'X' 已具有为 'Y' 定义的依赖项