2

I’m able to query the default document list in IIS using the following PowerShell code:

Get-WebConfigurationProperty -Filter "//defaultDocument/files/add" -PSPath 'MACHINE/WEBROOT/APPHOST' -Name "value" | select value

…but I want to disable the default document feature altogether to address a vulnerability. I’ve not found much on disabling the feature via PowerShell but MS documentation says the following can be run to remove a value:

remove-webconfigurationproperty /system.webServer/defaultDocument -name files -atElement @{value="foo.html"}

Is this really the only way to disable the feature? I’ve not found anything that suggests it can simply be disabled like you can in the IIS administration console.

2 Answers 2

1

To remove features from IIS, you should the Dism cmdlets, in your case:

Disable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument

If you want to disable it inside of IIS for the whole server, you can use:

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/defaultDocument" -name "enabled" -value "False"
3
  • Thanks so much. Works a treat! Is this process documented anywhere? I've been searching the web for some time now and not found the above or anything near to this!
    – jshizzle
    Commented Nov 24, 2020 at 18:24
  • I don't think every possible configuration change in IIS is documented, I just know it pretty well, so I can figure out how to do things based on previous experience. Commented Nov 24, 2020 at 18:29
  • Ok thanks. I like to get a good understanding of how to do the things I want but as mentioned, didn't find a lot for this cmdlet. Thanks again.
    – jshizzle
    Commented Nov 24, 2020 at 18:32
0

If you want to disable only for 1 site, use the following code:

Set-WebConfigurationProperty -filter "system.webserver/defaultdocument" -pspath "IIS:\sites\Default Web Site" -name "enabled" -Value "False"

Replace Default Web Site with the name of the site you want to disable

Credit to Peter for the original answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .