2011-01-26 9 views
1

IIS6の物理フォルダで 'ディレクトリブラウジング'を有効にするには、powershellスクリプトが必要です。重要な点は、変更したいフォルダが別の物理フォルダのサブフォルダであることです。いずれのフォルダも「仮想ディレクトリ」ではありません。Powershell - IIS6の物理フォルダで 'ディレクトリブラウジング'を有効にする

私は以下を試みましたが、DirectoryEntryは空です。私はそれがフォルダが "仮想ディレクトリ"ではないと仮定します。

$oDir = New-Object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/Test/Upgrade") 

# Loop thru all even though there should only be one... 
foreach ($oDirEntry in $oDir) 
{ 
    Write-Host "Enabling Directory Browsing on IIS folder [" $oDirEntry.Name "]." 
    $oDirEntry.put("EnableDirBrowsing",$true) 
    $oDirEntry.psbase.CommitChanges()   
} 

答えて

1

これは、これまでに書かれたきれいなコードではありませんが、私は多くの異なる反復をしようとしたこの作品一つです...

$sFolderName = "Test" 
$sSubFolderName = "SubTest" 
$oSubFolder = $null 

# Get reference to root website 
$oService = new-object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root") 

foreach ($oChild in $oService.children) 
{ 
    if ($oChild.Name -eq $sFolderName) 
    { 
     # Check if we already have an IIsWebDirectory named $sSubFolderName 
     foreach ($oChild2 in $oChild.children) 
     { 
      if ($oChild2.Name -eq $sSubFolderName) 
      { 
       $oSubFolder = $oChild2 
      } 
     } 

     # Create one if it doesn't exist 
     if ($oSubFolder -eq $null) 
     { 
      $oSubFolder = $oChild.Children.Add($sSubFolderName, "IIsWebDirectory") 
      $oSubFolder.psbase.CommitChanges() 
     } 

     $oSubFolder.Put("AccessRead",$true) 
     $oSubFolder.Put("EnableDirBrowsing",$true) 
     $oSubFolder.psbase.CommitChanges()  
    } 
} 
関連する問題