SOLVED: Find web sites and applications using a Microsoft IIS server application pool using the WebAdministration PowerShell cmdlets

If you're using the older WebAdministration PowerShell module for IIS you'll notice when browing application pools you'll see the applications in the pool.


https://learn.microsoft.com/powershell/module/webadministration



However when you try and get the applications property it's not there because it's provided as a formatted property. You can grab the code from inside the formatter however there is a simpler method by enumerating the web sites and applications - these can be returned in the format

SiteName

or

SiteName\ApplicationName

# Gets the names of the applications in the specified application pool.
Function Get-ApplicationPoolApplicationNames
{
    [CmdletBinding()]
    param(

        [Parameter()]
        [System.Object] $ApplicationPoolName

    )
    process
    {
        $applicationNames = New-Object System.Collections.Generic.List``1[System.String];
        $webSites = Get-Website;
        foreach ($webSite in $webSites)
        {    
            if ($webSite.applicationPool -eq $ApplicationPoolName) { $applicationNames.Add($webSite.Name); }
            $applications = Get-WebApplication -Site $webSite.Name;
            foreach ($application in $applications)
            {
                if ($application.applicationPool -eq $ApplicationPoolName)
                {
                    $applicationNames.Add("$($webSite.Name)$($application.Path)");
                }
            }
        }
        return $applicationNames;
    }
}


Comments

Popular posts from this blog

Windows Server 2016, 2019, 2022, Windows 10 and Windows 11: Date and time "Some settings are managed by your organization".

TFTPD32 or TFTPD64 reports Bind error 10013 An attempt was made to access a socket in a way forbidden by its access permissions.

Enable function lock for F1-F12 on HP ZBook mobile workstations