How to Restart a Single IIS Website via Command Line (IIS7+)


1 views

Many administrators reach for iisreset when needing to restart IIS services, but this brute-force approach restarts all websites and application pools. In production environments, we often need surgical control to restart just one problematic website without affecting others.

For IIS7+, we use PowerShell cmdlets from the WebAdministration module:

Import-Module WebAdministration
Stop-WebSite -Name "YourSiteName"
Start-WebSite -Name "YourSiteName"

For environments without PowerShell, the legacy appcmd utility still works:

%windir%\system32\inetsrv\appcmd stop site "YourSiteName"
%windir%\system32\inetsrv\appcmd start site "YourSiteName"

For more control, combine with application pool recycling:

# Restart site and its app pool
Stop-WebAppPool -Name "AppPoolName"
Stop-WebSite -Name "SiteName"
Start-WebAppPool -Name "AppPoolName"
Start-WebSite -Name "SiteName"

Wrap commands in try-catch blocks for production scripts:

try {
    Stop-WebSite -Name "CriticalSite" -ErrorAction Stop
    Start-WebSite -Name "CriticalSite" -ErrorAction Stop
}
catch {
    Write-EventLog -LogName Application -Source "IIS Manager" -EntryType Error -EventId 100 -Message $_.Exception.Message
}

Create a scheduled task that runs during maintenance windows:

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -Command "& {Import-Module WebAdministration; Stop-WebSite -Name 'NightlyMaintenanceSite'; Start-WebSite -Name 'NightlyMaintenanceSite'}""
Register-ScheduledTask -TaskName "IIS Site Restart" -Action $action -Trigger (New-ScheduledTaskTrigger -Daily -At 2AM)

When managing IIS websites, administrators often need to restart individual sites without affecting others. While the IIS Manager GUI provides this functionality (as shown in the reference image), automating this process through command line becomes crucial for scripting and remote management.

The recommended approach for IIS7 and later versions is using the appcmd.exe tool, which replaces older methods like iisweb.vbs. This powerful command-line tool is installed with IIS and located in %windir%\system32\inetsrv.

%windir%\system32\inetsrv\appcmd stop site "YourSiteName"
%windir%\system32\inetsrv\appcmd start site "YourSiteName"

Alternatively, you can combine these into a single line:

%windir%\system32\inetsrv\appcmd recycle apppool /apppool.name:"YourAppPoolName"

1. Restarting by site name:

appcmd stop site "Default Web Site" & appcmd start site "Default Web Site"

2. Restarting by site ID (useful when names might contain special characters):

appcmd stop site /id:1 & appcmd start site /id:1

3. Creating a reusable batch script (restart_site.bat):

@echo off
set SITE_NAME=%1
if "%SITE_NAME%"=="" (
    echo Usage: %0 "Site Name"
    exit /b 1
)

%windir%\system32\inetsrv\appcmd stop site "%SITE_NAME%"
%windir%\system32\inetsrv\appcmd start site "%SITE_NAME%"

For more complex scenarios, consider these approaches:

1. Checking site status before restart:

appcmd list site "YourSiteName" | find "state"

2. Restarting associated application pools:

for /f "tokens=3 delims= " %%A in ('appcmd list app "YourSiteName/" /text:apppool.name') do (
    appcmd recycle apppool /apppool.name:"%%A"
)

If you encounter issues:

  • Verify the site name exactly matches what's in IIS (case-sensitive)
  • Run Command Prompt as Administrator
  • Check IIS logs in %SystemDrive%\inetpub\logs\LogFiles
  • Use appcmd list site to verify correct site names/IDs

For modern systems, PowerShell provides more flexibility:

Import-Module WebAdministration
Restart-WebItem 'IIS:\Sites\Default Web Site' -Verbose

Or using the IIS Administration Cmdlets:

Stop-IISSite -Name "Default Web Site" -Confirm:$false
Start-IISSite -Name "Default Web Site"