Blog Post

IIS Support Blog
4 MIN READ

Managing IIS in PowerShell 7: Fixing Get-IISAppPool & Get-IISSite Issues

DeepakParashar's avatar
May 23, 2025

Managing Internet Information Services (IIS) with PowerShell is a common task for system administrators and developers. Commands like Get-IISAppPool and Get-IISSite are essential for retrieving application pools and websites. However, if you're using PowerShell 7 (PowerShell Core), you might run into compatibility issues with the IISAdministration and WebAdministration modules, leading to errors like the one shown below:

 

In this article, we’ll explore the root cause of this issue and provide two solutions: one for PowerShell 7 using the Microsoft.Web.Administration .NET API, and another for Windows PowerShell using the native IISAdministration module.

The Problem: Compatibility Issues in PowerShell 7

The screenshot above shows a typical error when running Get-IISAppPool in PowerShell 7. The command fails with the message: "Get-IISAppPool: The term 'Get-IISAppPool' is not recognized as a name of a cmdlet, function, script file, or executable program." Additionally, importing the WebAdministration module results in a warning: "Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects."

Root Cause

The IISAdministration and WebAdministration modules were designed for Windows PowerShell (version 5.1) and rely on .NET Framework assemblies like Microsoft.Web.Administration. PowerShell 7, which uses .NET Core, runs these modules in a compatibility session (WinPSCompatSession), leading to deserialized objects, performance issues, and sometimes outright failures. This is why Get-IISAppPool and Get-IISSite don’t work natively in PowerShell 7.

Solution 1: PowerShell 7-Compatible Approach Using Microsoft.Web.Administration

To manage IIS in PowerShell 7 without compatibility issues, you can directly use the Microsoft.Web.Administration .NET API. This approach bypasses the need for the IISAdministration module and works seamlessly in PowerShell 7.

Prerequisites

Ensure IIS is installed on the system, as the scripts rely on the Microsoft.Web.Administration.dll file, typically located at C:\Windows\System32\inetsrv\.

Script to List Application Pools (Equivalent to Get-IISAppPool)

try {
    # Load the Microsoft.Web.Administration assembly
    Add-Type -Path "C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll" -ErrorAction Stop

    # Create a ServerManager instance
    $serverManager = New-Object Microsoft.Web.Administration.ServerManager

    # Get all application pools
    $appPools = $serverManager.ApplicationPools

    # Display application pool names and states
    if ($appPools) {
        Write-Output "Application Pools found:"
        foreach ($appPool in $appPools) {
            Write-Output "Application Pool: $($appPool.Name), State: $($appPool.State)"
        }
    } else {
        Write-Output "No application pools found."
    }
}
catch {
    Write-Error "Failed to list application pools: $_"
}

Script to List Websites (Equivalent to Get-IISSite)

try {
    # Load the Microsoft.Web.Administration assembly
    Add-Type -Path "C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll" -ErrorAction Stop

    # Create a ServerManager instance
    $serverManager = New-Object Microsoft.Web.Administration.ServerManager

    # Get all websites
    $sites = $serverManager.Sites

    # Display website names and states
    if ($sites) {
        Write-Output "Websites found:"
        foreach ($site in $sites) {
            Write-Output "Website: $($site.Name), State: $($site.State)"
        }
    } else {
        Write-Output "No websites found."
    }
}
catch {
    Write-Error "Failed to list websites: $_"
}

Solution 2: Using Windows PowerShell with IISAdministration Module

If you prefer to use the native IISAdministration module, you’ll need to switch to Windows PowerShell (version 5.1), which is fully compatible with the module.

Steps

  1. Open Windows PowerShell as Administrator:
    • From Command Prompt, run:
      %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
    • Verify the version:
      $PSVersionTable.PSVersion
      You should see a Major version of 5.1.
  2. Ensure Required IIS Features Are Installed:
    • Run the following to enable necessary IIS management tools:
      Dism /Online /Enable-Feature /FeatureName:IIS-WebServerManagementTools /All /NoRestart
      Dism /Online /Enable-Feature /FeatureName:IIS-ManagementScriptingTools /All /NoRestart
    • Check for a pending reboot:
      if (Test-Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") { Write-Warning "A reboot is required. Please restart the server." }
  3. Install and Import the IISAdministration Module:
    Install-Module -Name IISAdministration -Force
    Import-Module IISAdministration -Force
  4. Run the Commands:
    • List application pools:
      Get-IISAppPool
    • List websites:
      Get-IISSite

Best Practices for Production Environments

  • Test First: Always test scripts in a staging environment before running them in production, as enabling IIS features may require a server reboot.
  • Backup IIS Configuration:
    "C:\Windows\System32\inetsrv\appcmd.exe" add backup "PreScriptBackup"
  • Run as Administrator: Ensure PowerShell is running with elevated privileges, as IIS management tasks require administrative access.
  • Schedule Maintenance: If a reboot is needed, schedule a maintenance window to avoid downtime.

Conclusion

Managing IIS in PowerShell 7 requires a different approach due to compatibility issues with the IISAdministration and WebAdministration modules. By using the Microsoft.Web.Administration .NET API, you can achieve the same functionality as Get-IISAppPool and Get-IISSite in a PowerShell 7-compatible way. For those who prefer the native modules, switching to Windows PowerShell provides a seamless experience.

Published May 23, 2025
Version 1.0

1 Comment

  • JaredC's avatar
    JaredC
    Copper Contributor

    Thank you! This was driving me nuts because I’m trying to get app pools running as a specific service account and using the module was returning nothing when getting the process model properties. This fixed it.