Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enumerate IIS websites using Powershell and find the app pool for each?

I can search for websites using:

Get-WmiObject -Namespace "root\WebAdministration" -Class Site -Authentication PacketPrivacy -ComputerName $servers

And I can list the app pools using:

Get-WmiObject -computer $servers -Namespace root\MicrosoftIISv2 -Class IIsApplicationPoolSetting -Impersonation Impersonate -Authentication PacketPrivacy

How can I link these together to find which app pool is associated to which website? It's a Windows Server 2008 R2 server with IIS 7.5.

like image 660
Chris Reeve Avatar asked Aug 01 '14 21:08

Chris Reeve


People also ask

How do I get a list of IIS sites?

Using the Get-IISSite cmdlet, you can easily query the IIS webserver to get a list of IIS websites and configuration details about websites like website name, IIS website status, IIS website Physical Path and IIS website bindings information.

How do I navigate to IIS in PowerShell?

Start the IIS PowerShell Management ConsoleManagement ConsoleYou use Microsoft Management Console (MMC) to create, save and open administrative tools, called consoles, which manage the hardware, software, and network components of your Microsoft Windows operating system. MMC runs on all client operating systems that are currently supported.https://learn.microsoft.com › system-management-componentsWhat is MMC - Windows Server - Microsoft Learn. Click on the Start Menu - select "All Programs" - "IIS 7.0 Extensions" - "IIS PowerShell Management Console". The prompt of the new PowerShell command window is set to "IIS:" - the root of the IIS Provider namespace.


2 Answers

Use the webadministration module:

Import-Module WebAdministration

dir IIS:\Sites # Lists all sites
dir IIS:\AppPools # Lists all app pools and applications


# List all sites, applications and appPools

dir IIS:\Sites | ForEach-Object {

    # Web site name
    $_.Name

    # Site's app pool
    $_.applicationPool

    # Any web applications on the site + their app pools
    Get-WebApplication -Site $_.Name
}
like image 104
Avner Avatar answered Sep 20 '22 22:09

Avner


Here's another option if you do not want to use the IIS:\ path.

$site = Get-IISSite -Name 'my-site'
$appPool = Get-IISAppPool -Name $site.Applications[0].ApplicationPoolName
like image 23
Mike Veazie - MSFT Avatar answered Sep 18 '22 22:09

Mike Veazie - MSFT