Stopping IIS websites permanently with PowerShell
Stopping websites using Stop-Website is, apparently, not the same as stopping them using the IIS Manager.
Stop-Website 'Some site'
iisreset.exe
# site is started again
Using IIS Manager, the state is the same after a reset/reboot. I guess stopping a site using IIS Manager modifies some sort of persistent configuration (the registry?).
Can anyone tell me how I can use PowerShell to stop a site permanently, so that a reset/reboot does not bring the site online again?
(Stop-WebAppPool exhibits exactly the same behavior.)
Joseph's answer makes perfect sense, but it doesn't seem to work.
The attribute 'serverAutoStart' on the site node in applicationHost.config
is not changed.
One way to change is:
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='Default Web Site']" -name "serverAutoStart" -value "False"
but that's a mouthful.
Another way is:
Set-ItemProperty "IIS:\Sites\Default Web Site" serverAutoStart False
It's also interesting that this attribute is not directly editable in IIS Manager, you have to go into the Configuration Editor
to change it.
Yes, starting or stopping the site in IIS Manager changes that attribute, but that's not obvious to the user.
Let's try this:
$site = Get-Item 'IIS:\sites\Default Web Site'
$site.serverAutoStart = $False
$site.Stop()
Obviously, Default Web Site
needs to be replaced. ;-)
I don't have a test lab setup for this, so let me know if it works for you.
There are a ton of options in the IIS PSProvider ... run the following to explore a bit more:
$site = Get-Item 'IIS:\sites\Default Web Site'
$site | get-member