not*_*ndy 5 windows powershell windows-server-2008 iis-7
我想要一个显示以下内容的应用程序或脚本:工作进程、应用程序池名称、内存使用情况和可选的 CPU 使用情况。我熟悉使用
%windir%\system32\inetsrv\appcmd.exe list wp
但这只会让我获得 workerproces id 和应用程序池名称。然后我把它和交叉引用任务管理器。这有效,但我想要一个更快的 - 几乎像信息显示一样的仪表板。我想一定有某种解决方案可以显示信息而无需像流程浏览器那样点击。任何人都有他们特别使用的东西?这在powershell中可能吗?
如果您没有 IIS 7 和提供程序,则可以使用 WMI。附加的脚本可以满足您的大多数要求(CPU 使用率除外)。将以下脚本保存为 get-webserverapppoolstats.ps1 (或任何您想要的)。
然后您可以使用以下命令运行该脚本:
./Get-WebServerAppPoolStats.ps1 'Server1'、'Server2'、'Server3' -IntegratedAuthentication 或 Get-Contentservers.txt | ./Get-WebServerAppPoolStats.ps1 -IntegratedAuthentication
param (
$webserver = $null,
$username,
$password,
[switch]$IntegratedAuthentication)
BEGIN
{
$path = $MyInvocation.MyCommand.Path
if ($webserver -ne $null)
{
if ($IntegratedAuthentication)
{
$webserver | &$path -IntegratedAuthentication
}
else
{
$webserver | &$path -username $username -password $password
}
}
$OFS = ', '
$Fields = 'CommandLine', 'Name', 'CreationDate', 'ProcessID', 'WorkingSetSize', 'ThreadCount', 'PageFileUsage', 'PageFaults'
$query = @"
Select $fields
From Win32_Process
Where name = 'w3wp.exe'
"@
$AppPool = @{Name='Application Pool';Expression={($_.commandline).split(' ')[-1]}}
$Process = @{Name='Process';Expression={$_.name}}
$RunningSince = @{Name='Running since';Expression={[System.Management.ManagementDateTimeconverter]::ToDateTime($_.creationdate)}}
$Memory = @{Name='Memory Used';Expression={'{0:#,#}' -f $_.WorkingSetSize}}
$Threads = @{Name='Thread Count';Expression={$_.threadcount}}
$PageFile = @{Name='Page File Size';Expression={'{0:#,#}' -f $_.pagefileusage}}
$PageFaults = @{Name='Page Faults';Expression={'{0:#,#}' -f $_.pagefaults}}
}
PROCESS
{
$server = $_
if ($server -ne $null)
{
if ($IntegratedAuthentication)
{
$result = Get-WmiObject -Query $query -ComputerName $server
}
else
{
$securepassword = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securepassword
$result = Get-WmiObject -Query $query -ComputerName $server -Credential $cred
}
$Server = @{Name='Server';Expression={$server}}
$result | Select-Object $Server, $AppPool, $Process, $RunningSince, $Memory, $Threads, $PageFile, $pageFaults
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8397 次 |
| 最近记录: |