IIS (Internet Information Services) · Operations

Command-Line Management (appcmd and PowerShell)

Clicking through IIS Manager doesn’t scale. Scripts make server setup repeatable, reviewable and fast.

Advanced 5 min Lesson 30 of 33Covers IIS 10 on Windows Server 2019/2022/2025 and Windows 10/11.
Before you start:Application Pools
0/33 in IIS
On this page · 5 min · Advanced

In simple words#

IIS Manager is driving with a manual map; scripts are a saved GPS route — the same journey every time, on every server, without wrong turns.

appcmd.exe
Classic IIS command-line tool in inetsrv.
WebAdministration
PowerShell module with IIS:\ drive and *-Web* cmdlets.
IISAdministration
Newer, faster PowerShell module (*-IIS* cmdlets).

Learning objectives#

  • Use appcmd for quick tasks
  • Use the IIS:\ PowerShell drive
  • Use IISAdministration for sites and bindings
  • Write an idempotent setup script

Explanation#

appcmd lives in %windir%\System32\inetsrv. Verbs: list, add, set, delete, start, stop, recycle on objects site, apppool, app, vdir, config, wp.

WebAdministration gives the IIS:\ drive (IIS:\Sites, IIS:\AppPools) and cmdlets like New-WebAppPool, New-Website, Set-ItemProperty.

IISAdministration (Get-IISSite, New-IISSite, Get-IISConfigSection) works directly with the configuration system and is faster for large changes.

Write scripts that check whether objects exist before creating them, so they can run repeatedly.

Code example: Idempotent site setup#

PowerShellsetup-shop.ps1 Illustrative
Import-Module WebAdministration
$pool = 'ShopPool'; $site = 'Shop'; $path = 'C:\inetpub\shop'


if (-not (Test-Path "IIS:\AppPools\$pool")) { New-WebAppPool -Name $pool | Out-Null }
Set-ItemProperty "IIS:\AppPools\$pool" managedRuntimeVersion ''
Set-ItemProperty "IIS:\AppPools\$pool" startMode 'AlwaysRunning'


New-Item -ItemType Directory -Force $path | Out-Null
if (-not (Get-Website -Name $site)) {
  New-Website -Name $site -PhysicalPath $path -ApplicationPool $pool -HostHeader 'shop.example.com' -Port 80 | Out-Null
}


# Quick checks with appcmd
$appcmd = "$env:windir\System32\inetsrv\appcmd.exe"
& $appcmd list site /name:$site
& $appcmd list apppool /name:$pool /text:state
Expected output
SITE "Shop" (id:3,bindings:http/*:80:shop.example.com,state:Started)
Started

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. The pool is created only if missing, then configured.
  2. The site is created only if missing.
  3. Running the script twice changes nothing — it is idempotent.
  4. appcmd confirms the result.

Real-world use case#

A team rebuilds a failed server in 10 minutes by running its IIS setup scripts from Git.

Common mistakes#

Scripts that fail on the second run

Check for existence before creating objects.

Mixing manual changes with scripts

Manual changes drift. Update the script instead.

Best practices#

  • Keep IIS setup scripts in Git
  • Make scripts idempotent
  • Use IISAdministration for bulk changes
  • Run as Administrator

Remember this#

appcmd list/add/set/start/stop/recycle.

IIS:\Sites and IIS:\AppPools drives.

Scripts > clicks for servers.

Practice exercise#

Your task: List all app pools and their state with appcmd.

Show solution
PowerShell Illustrative
& "$env:windir\System32\inetsrv\appcmd.exe" list apppool

Mini quiz#

Command-Line Management (appcmd and PowerShell) quizMultiple choice Question 1 of 1

Which PowerShell drive does the WebAdministration module provide?

Score so far: 0/0

Want more? Practise all IIS MCQs · IIS interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.