When managing IIS websites through PowerShell, many administrators discover that Stop-Website
behaves differently than the IIS Manager GUI. The command only stops the site temporarily - any IIS reset (iisreset.exe
) or server reboot will restart the site automatically.
# Temporary stop (won't persist after reset)
Stop-Website "ProductionWebApp"
iisreset
# Site comes back online!
The IIS Manager actually modifies the site's persistent configuration in applicationHost.config (typically located at %windir%\system32\inetsrv\config\applicationHost.config
), while Stop-Website
only changes the runtime state.
To achieve the same permanent stop behavior as IIS Manager, we need to modify the site's serverAutoStart
property:
Import-Module WebAdministration
Set-ItemProperty "IIS:\Sites\ProductionWebApp" -Name serverAutoStart -Value $false
Stop-Website "ProductionWebApp"
For environments without WebAdministration module:
# Disable auto-start
%windir%\system32\inetsrv\appcmd.exe set site "ProductionWebApp" /serverAutoStart:false
# Stop immediately
%windir%\system32\inetsrv\appcmd.exe stop site "ProductionWebApp"
Check your changes in applicationHost.config:
# Should show serverAutoStart="false"
Select-String -Path "$env:windir\system32\inetsrv\config\applicationHost.config" -Pattern "ProductionWebApp"
For multiple sites, use PowerShell pipeline:
Get-ChildItem IIS:\Sites | Where-Object { $_.Name -like "*Test*" } | ForEach-Object {
Set-ItemProperty $_.PSPath -Name serverAutoStart -Value $false
Stop-Website $_.Name
}
To reverse the changes:
Set-ItemProperty "IIS:\Sites\ProductionWebApp" -Name serverAutoStart -Value $true
Start-Website "ProductionWebApp"
Many administrators discover that using PowerShell's Stop-Website
cmdlet doesn't actually persist the stopped state across IIS resets or server reboots. This behavior differs from manually stopping sites in IIS Manager, which maintains the stopped state persistently.
# Temporary stop (doesn't persist)
Stop-Website 'MyWebsite'
iisreset
# Website comes back online automatically
The key difference lies in how these methods interact with IIS configuration. Stop-Website
only changes the runtime state, while IIS Manager modifies the underlying configuration in applicationHost.config
.
To make website stops persistent, we need to modify the server configuration directly. Here's the PowerShell approach:
# 1. Import WebAdministration module
Import-Module WebAdministration
# 2. Get the website object
$site = Get-Item "IIS:\Sites\MyWebsite"
# 3. Set the serverAutoStart property to false
$site.serverAutoStart = $false
# 4. Commit the changes
$site | Set-Item
For those who prefer command-line tools, you can achieve the same result with:
appcmd set site "MyWebsite" /serverAutoStart:false
After making these changes, you can verify the setting in applicationHost.config
:
# Location: %windir%\system32\inetsrv\config\applicationHost.config
# Look for:
<site name="MyWebsite" serverAutoStart="false">
When you want the site to auto-start again:
# PowerShell method
$site = Get-Item "IIS:\Sites\MyWebsite"
$site.serverAutoStart = $true
$site | Set-Item
# Or using AppCmd
appcmd set site "MyWebsite" /serverAutoStart:true
- This method requires administrative privileges
- Changes affect the site's behavior after any service restart
- Works for both websites and application pools (using similar properties)
- Doesn't immediately stop running instances - combine with Stop-Website if needed