views:

43

answers:

1

I'm using the PowerShell script below to set anonymous user identity and authentication methods on an IIS6 server. The script seems to work at first, but if I issue an iisreset after running it the values revert to the old ones! How do I persist them?

 $server = "localhost"
 $siteName = "www.mysite.com"
 $iis = [ADSI]"IIS://$server/W3SVC"
 $site = $iis.children | where { $_.keyType -eq "IIsWebServer" -and $_.ServerComment -eq $siteName }
 $path = [ADSI]($site.path+"/ROOT")
 $path.AnonymousUserName = "user"
 $path.AnonymousUserPass = "pass"
 $path.AuthFlags = 3
 $path.CommitChanges()
A: 

Turns out the metabase is not persisted at once. iisreset forces shutdown of the IIS services and the information is lost.

There are two ways of fixing this:

  1. Run C:\WINDOWS\system32\IIsCnfg.vbs /save
  2. net stop and then net start
Crassy