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

2
  • I assume Remove-Website is not what you want to do? Jul 3 '15 at 14:32
  • 1
    No, that's a tad too destructive :). This is to temporarily stop a site, but not just until the next reset.
    – Bergius
    Jul 3 '15 at 14:37
15

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.

7
  • Hmmmm ... :D I wonder if that just modifies it in memory ... Set-ItemProperty seems more canonical anyway. good catch! Jul 4 '15 at 4:57
  • The autostart property is in the IIS Manager, right click on the web site -> "Manage Web Site" -> "Advanced Settings..." -> "Start Automatically" Jul 4 '15 at 5:07
  • @JosephKern - Hmm, I don't see that, not on my 2012 R2 or 2016. Under what heading is that listed General? Jul 4 '15 at 5:38
  • Not sure why you don't see it ... I have it on 2008R2 IIS7 Jul 4 '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? Jul 5 '15 at 3:30
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
6
  • Does not compute, as far as I can tell. serverAutoStart lives in applicationHost.config, and changes to a ConfigurationElement object are not persisted.
    – Bergius
    Jul 3 '15 at 15:13
  • I could probably modify applicationHost.config manually, but that smells all kinds of wrong :).
    – Bergius
    Jul 3 '15 at 15:15
  • See Peters post, Set-ItemProperty looks like what you want. I was oh so close ... ;-) Jul 4 '15 at 5:09
  • 1
    @JosephKern - close enough to still get up-votes, :-) This doesn't work kids. Jul 5 '15 at 17:24
  • 1
    Upvote was mine, because it was correct in spirit :). The solution is accepted and here for everyone to see, so I don't see the harm in rewarding Joseph's effort.
    – Bergius
    Jul 6 '15 at 15:41
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.