Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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
    }
}
share|improve this answer
    
I changed $AppPool = @{Name='Application Pool';Expression={($_.commandline).split('"')[-2]}} so it works with app pools with spaces in their names. –  notandy Dec 30 '10 at 19:43

Yes powershell can do this with the new powershell provider for IIS it's easy. Here are some of the examples from the run time data walkthru's provided:

AppPool State

PS IIS:\> cd AppPools
PS IIS:\AppPools> Get-WebItemState DemoAppPool
Started
PS IIS:\AppPools> Stop-WebItem DemoAppPool
PS IIS:\AppPools> Get-WebItemState DemoAppPool
Stopped

Worker Processes and Requests The get-process cmdlet doesn't help you figuring out which Application Pool a particular worker process is serving. This can be easily done however:

PS IIS:\AppPools> dir DefaultAppPool\WorkerProcesses

               processId                  Handles                    state StartTime
               ---------                  -------                    
                   6612                      326                        1 3/28/2008 12:20:27 PM

note that once you have the PID regular

   get-process -id pid

will tell you the memory usage

share|improve this answer

I dont know why the Server 'name' part of this script didn't work for me, but i came up with a workaround:

replace this line:

$Server = @{Name='Server';Expression={$server}}

with these two lines:

$machine = New-Object system.string $server

$Server = @{Name='Server';Expression={$machine}}

once i did this, it worked perfectly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.