如何使用PowerShell在IIS中设置默认文档?

时间:2022-12-15 01:51:38

I'm configuring a web site using PowerShell and I want to set the default document. How do I do this?

我正在使用PowerShell配置网站,我想设置默认文档。我该怎么做呢?

1 个解决方案

#1


This is one way:

这是一种方式:

$metabasePath = "IIS://Localhost/W3SVC"
$iisNumber = "12345"
$site = new-object 
        System.DirectoryServices.DirectoryEntry("$metabasePath/$iisNumber/root")
$site.psbase.Properties["DefaultDoc"].Value = 
    "newdefdoc.htm," + $site.psbase.Properties["DefaultDoc"].Value
$site.psbase.CommitChanges()

The value returned in $site.psbase.Properties["DefaultDoc"].Value is a comma separated list of documents so you may need to re-jig the order to suit your case. The example above just adds a new default document (newdefdoc.htm) to the top of the list.

$ site.psbase.Properties [“DefaultDoc”]中返回的值.Value是以逗号分隔的文档列表,因此您可能需要重新编写订单以适合您的情况。上面的示例只是在列表顶部添加了一个新的默认文档(newdefdoc.htm)。

#1


This is one way:

这是一种方式:

$metabasePath = "IIS://Localhost/W3SVC"
$iisNumber = "12345"
$site = new-object 
        System.DirectoryServices.DirectoryEntry("$metabasePath/$iisNumber/root")
$site.psbase.Properties["DefaultDoc"].Value = 
    "newdefdoc.htm," + $site.psbase.Properties["DefaultDoc"].Value
$site.psbase.CommitChanges()

The value returned in $site.psbase.Properties["DefaultDoc"].Value is a comma separated list of documents so you may need to re-jig the order to suit your case. The example above just adds a new default document (newdefdoc.htm) to the top of the list.

$ site.psbase.Properties [“DefaultDoc”]中返回的值.Value是以逗号分隔的文档列表,因此您可能需要重新编写订单以适合您的情况。上面的示例只是在列表顶部添加了一个新的默认文档(newdefdoc.htm)。