I'm currently working on a deployment script that will take my site, export it from svn, remove any testing files etc in it, minify the javascript/css, copy the code to a remote web server, and then switch the physical path of the existing site to the new directory.
So far I have everything working except for switching the physical directory in IIS.
$IIsServer = Get-WmiObject Site -Namespace "root/WebAdministration" -ComputerName $serverIP -Credential $credentials -Authentication PacketPrivacy
$site = $IIsServer | Where-Object {$_.Name -eq $siteName}
When I look into the values I have I cant find the physical path property.
Any suggestions would be greatly appreciated.
This also works:
(Note the use of backticks for line continuations)
I'd like to build on top of @Kev's post.
You can use his method locally, but as he says there's no real way of providing credentials for his commented-out method of remotely connecting:
$serverManager = [Microsoft.Web.Administration.ServerManager]::OpenRemote($serverIP)
To change the physical path remotely, with credentials, use the following:
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.You'll notice there's a commented out line which might work for you if you need to do this remotely:
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: