Get IIS Application Pool ‘Private Memory’ value remotely

Private memory results

Recently I was asked to check Private Memory in all application pools settings. As I’m working mostly on server core machines I had to do this using PowerShell script.

Private Memory

Private memory is the Maximum amount of memory (in KB) a worker process can consume before causing an application pool to recycle.

Private Memory restricts web applications to consume more memory than the assigned limit. Default application pools have private memory of 0 KB, means there is no limit. According to your server resources, you can run as many websites as you wish under the default application pool.

To view this value we have to navigate to advanced settings in IIS and scroll to Private Memory Limit (KB):

Private Memory

If you have multiple machines and want to check quickly what value was configured there you can use the below script. It is based on Get-WebConfiguration command from webadministration module. Final results are added to an array:

        # Server list
        $Servers = Get-Content -path "D:\scripts\input.txt" 
        $FinalResults = @()

        # Checking all servers
        $FinalResults = Invoke-Command -cn $Servers {
                $applicationPoolsPath = "/system.applicationHost/applicationPools"
                $applicationPools = Get-WebConfiguration $applicationPoolsPath
                foreach ($appPool in $applicationPools.Collection){
                    $appPoolPath = "$applicationPoolsPath/add[@name='$($appPool.Name)']"
                    $Result = Get-WebConfiguration "$appPoolPath/recycling/periodicRestart/@privateMemory" 
                        $Object = @{} | select Application,Name,Value
                        $AppName = ($result.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1').Trim()
                        $Object.Application = $AppName 
                        $Object.Name  = $
                        $Object.Value = $Result.value
        } | select @{n='ServerName';e={$_.pscomputername}},Application,Name,Value

        # Display results in new window
        $FinalResults | Out-GridView -Title "Private Memory"

        # Display results in console
        $FinalResults | Format-Table -Auto

        # Export to CSV on your desktop
        $FinalResults | Export-Csv $env:userprofile\desktop\private_memory.csv -Force -NoTypeInformation 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.