سؤال

I'm trying to write a script to disable directory browsing on ALL directories /virtual directories and on an IIS website.

I've tried using ADSI in PowerShell but am having a hard time understanding how to enumerate current directories and not sure how to change the property on Directory Browsing to false.

هل كانت مفيدة؟

المحلول

$iis = [ADSI]"IIS://$ComputerName/W3SVC/1/ROOT"

# list directories
$iis.Children | select name,@{n='DirBrowsingEnabled';e={$_.psbase.InvokeGet('EnableDirBrowsing')}}

# disable directory browsing on all directories
$iis.Children | where {!$_.psbase.InvokeGet('EnableDirBrowsing')} | foreach {
    $_.put('EnableDirBrowsing',$false)
    $_.psbase.CommitChanges()
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top