views:

924

answers:

1

I'm trying to change a site's home directory using powershell. This is what I have so far, but it isn't saving the changes...

$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()

answered below..

+6  A: 
$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()
Recursieve
When I run this script (on Vista Business 64-bit), I get an "Access is denied" error in the call to $iis.psbase. Is it because I'm running IIS7 rather than 6? I'm developing on Vista, but the scripts will be running on 2K3 Server.
David Keaveny