Windows – Free application or script to monitor App pool memory usage

iis-7powershellwindowswindows-server-2008

I want an application or script that displays the following:
Worker process, App pool name, memory usage, and optionally cpu usage.
I am familiar with using

%windir%\system32\inetsrv\appcmd.exe list wp

but this just gets me the workerproces id and the app pool name. I then take that and cross reference taskmanager. This works, but I would like a quicker – almost dashboard like display of the information. I imagine there must be some sort of solution that shows the information without needing to click around like process explorer. Anyone have something in particular they use? Would this be possible in powershell?

Best Answer

If you don't have IIS 7 and the provider, you can use WMI. The attached script works for most of your requirements, except CPU usage. Save the below script as get-webserverapppoolstats.ps1 (or whatever you want).

You can run the script then with:

./Get-WebServerAppPoolStats.ps1 'Server1', 'Server2', 'Server3' -IntegratedAuthentication OR Get-Content servers.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
    }
}