使用Powershell更改IIS6站点主目录

时间:2008-12-01 11:57:29

标签: iis powershell scripting iis-6

我正在尝试使用PowerShell更改网站的主目录。这是我到目前为止所做的,但它没有保存更改......

$server = "localhost"
$siteName = "mysite"
$iis = [ADSI]"IIS://$server/W3SVC"
$site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" 
        -AND $_.ServerComment -eq $siteName }
$path = [adsi]($site.psbase.path+"/ROOT")

$path.path = "D:\Sites\mysite\www2"
$site.psbase.CommitChanges()

1 个答案:

答案 0 :(得分:12)

$server = "localhost"
$siteName = "mysite"
$iis = [ADSI]"IIS://$server/W3SVC"
$site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" 
        -AND $_.ServerComment -eq $siteName }
$path = [adsi]($site.psbase.path+"/ROOT")
$path.path
$path.psbase.properties.path[0] = "D:\Sites\$siteName\www2"
$path.path
$path.psbase.CommitChanges()