The problem with the root/WebAdministration WMI
provider is that it's not very feature rich.
What you can do is use the Microsoft.Web.Administration
managed API instead. This script will work if run on the server itself.
[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$siteName = "Default Web Site"
$serverIP = "your ip address"
$newPath = "your new path"
$serverManager = New-Object Microsoft.Web.Administration.ServerManager
## $serverManager = [Microsoft.Web.Administration.ServerManager]::OpenRemote($serverIP)
$site = $serverManager.Sites | where { $_.Name -eq $siteName }
$rootApp = $site.Applications | where { $_.Path -eq "/" }
$rootVdir = $rootApp.VirtualDirectories | where { $_.Path -eq "/" }
$rootVdir.PhysicalPath = $newPath
$serverManager.CommitChanges()
You'll notice there's a commented out line which might work for you if you need to do this remotely:
## $serverManager = [Microsoft.Web.Administration.ServerManager]::OpenRemote($serverIP)
Unfortunately MS didn't think to provide a way to supply credentials. This would mean that the account running the script would need all the right permissions granted on the remote server. I can't try this right now because I'm not near an AD environment.
The script itself will update the site root physical path (/
).
For more info about IIS7's configuration see the following link:
IIS7 Configuration Reference > system.applicationHost