Command-Line Management (appcmd and PowerShell)
Clicking through IIS Manager doesn’t scale. Scripts make server setup repeatable, reviewable and fast.
On this page · 5 min · Advanced
On this page
- In simple words
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Oct 30, 2026
Interview questions
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#
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
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#
- The pool is created only if missing, then configured.
- The site is created only if missing.
- Running the script twice changes nothing — it is idempotent.
- 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#
Check for existence before creating objects.
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
& "$env:windir\System32\inetsrv\appcmd.exe" list apppool
Mini quiz#
Which PowerShell drive does the WebAdministration module provide?
Want more? Practise all IIS MCQs · IIS interview questions
My notes#
Saved in this browser.