10

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.)

Bergius
  • 203
  • 2
  • 7

3 Answers3

16

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.

Peter Hahndorf
  • 14,058
  • 3
  • 41
  • 58
  • Hmmmm ... :D I wonder if that just modifies it in memory ... Set-ItemProperty seems more canonical anyway. good catch! – Joseph Kern Jul 04 '15 at 04:57
  • The autostart property is in the IIS Manager, `right click on the web site -> "Manage Web Site" -> "Advanced Settings..." -> "Start Automatically"` – Joseph Kern Jul 04 '15 at 05:07
  • @JosephKern - Hmm, I don't see that, not on my 2012 R2 or 2016. Under what heading is that listed `General`? – Peter Hahndorf Jul 04 '15 at 05:38
  • Not sure why you don't see it ... I have it on 2008R2 IIS7 – Joseph Kern Jul 04 '15 at 17:50
  • @JosephKern - I checked an older server with 2008 R2 and see it there but it's gone in newer versions. I wonder why? – Peter Hahndorf Jul 05 '15 at 03:30
  • You can do it all through Powershell now! There's no need to create a UI for anything /s. – Joseph Kern Jul 05 '15 at 04:41
  • Very nice, thank you. The reason I needed this: I've put together a script that collects all sites running on the specified machines, together with the timestamp for the last request. This is sent to Out-GridView -PassThru, so the user can select zero or more sites which will then be stopped. Handy for dev servers, in our case. – Bergius Jul 05 '15 at 16:11
2

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
Joseph Kern
  • 9,899
  • 4
  • 32
  • 56
0

I don't have the rep yet to comment, so posting this as an answer...

To make Joseph's suggestion work a Set-Item is needed to persist the change.

    $site = Set-Item

The full 4 lines to make default site stay stopped.

    $site = Get-Item 'IIS:\sites\Default Web Site'
    $site.serverAutoStart = $False
    $site.Stop()
    $site = Set-Item
AndOs
  • 103
  • 2