简体   繁体   English

使用 Powershell 获取 IIS 应用程序池 ProcessID

[英]Using Powershell to obtain an IIS Application Pool ProcessID

I have searched quite a bit for options to get the app Pool process id for a powershell script.我已经搜索了很多选项来获取 powershell 脚本的应用程序池进程 ID。 The issue I am having is most solutions I find point to using the WebAdministration WorkerProcess.我遇到的问题是我发现大多数解决方案都指向使用 WebAdministration WorkerProcess。 I tried the below script on Windows Server 2012 (IIS 8) and Windows Server 2019 (IIS 10).我在 Windows Server 2012 (IIS 8) 和 Windows Server 2019 (IIS 10) 上尝试了以下脚本。

Get-ChildItem -Path IIS:\AppPools |%{
    $AppPool = $_.Name
    Get-WmiObject -NameSpace 'root\WebAdministration' -class 'WorkerProcess' | Where-Object {$_.AppPoolName -match $AppPool} | Select-Object -Expand ProcessId | ForEach-Object {
            $AppPoolPID=$_
            $AppPoolProcces = Get-Wmiobject -Class Win32_PerfFormattedData_PerfProc_Process | Where-Object { $_.IdProcess -eq $AppPoolPID } 
            $AppPoolCpu = $AppPoolProcces.PercentProcessorTime
            $AppPoolMemory = [Math]::Round(($AppPoolProcces.workingSetPrivate / 1MB),2)
            $Cpu += $AppPoolCpu
            $Memory += $AppPoolMemory
            Write-Host "Application pool $AppPool process id: $_ Percent CPU: $Cpu Private Memory: $Memory"
    }
}

Running Get-WmiObject -NameSpace 'root\\WebAdministration' -List Provides a rather large list of items, but WorkerProcesses is not one of them.运行Get-WmiObject -NameSpace 'root\\WebAdministration' -List提供相当大的项目列表,但 WorkerProcesses 不是其中之一。

I've also tried dir IIS:\\AppPools\\$AppPool\\WorkerProcesses\\ which also provides no results.我也试过dir IIS:\\AppPools\\$AppPool\\WorkerProcesses\\也没有提供任何结果。

How can I get the processId of a specific application pool?如何获取特定应用程序池的 processId? or if that is no longer possible, how would I be able to get the cpu and memory consumption of specific application pools?或者如果这不再可能,我将如何获得特定应用程序池的 CPU 和内存消耗?

Try piping to get some extra info:尝试通过管道获取一些额外信息:

$id = dir IIS:\AppPools\MyAppPool\WorkerProcesses\ | Select-Object -expand processId
$id

Thanks @dai for pointing out that the process may not even be running due to lack of web requests.感谢@dai 指出由于缺乏网络请求,该进程甚至可能无法运行。 I was under the impression that it would always be running.我的印象是它会一直运行。

The script portion as I posted initially does actually work.我最初发布的脚本部分确实有效。 So for my purposes - no results is a good thing.所以就我而言 - 没有结果是一件好事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Powershell创建IIS 6.0应用程序池 - Creating an IIS 6.0 Application Pool using Powershell 使用PowerShell配置IIS应用程序池设置 - Configuring IIS application pool settings using PowerShell 使用Powershell在IIS中设置网站的应用程序池 - Setting a website's application pool in IIS using Powershell 如何使用powershell脚本启动和停止IIS中的应用程序池 - How to start and stop application pool in IIS using powershell script 使用PowerShell回收IIS应用程序池:“异常调用回收” - Recycling IIS application pool using PowerShell: “Exception calling Recycle” 使用PowerShell脚本时IIS应用程序池回收身份 - IIS Application Pool recycling Identity when using PowerShell script IIS PowerShell应用程序池设置为“NetworkService”帐户 - IIS PowerShell Application Pool set as 'NetworkService' Account 如何使用PowerShell在IIS 8.5中为特定用户创建应用程序池? - How do I create an application pool with specific user in IIS 8.5 using PowerShell? 使用PowerShell授予IIS 7.5应用程序池读取证书私钥的权限 - Grant IIS 7.5 Application Pool Read Permission to Certificate Private Key by Using PowerShell 如何使用PowerShell和Web管理模块检查IIS中是否存在应用程序池? - How to check whether an application pool exists or not in IIS using powershell and web administration module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM