Powershell – Changing physical path on IIS through appcmd isn’t activated

appcmddeploymentiis-7.5powershellscripting

We have come across an issue on IIS 7.5 where we have a simple deploy system which consists of the following:

Create a zip-file of new webroot, consisting of three folders:

Api
Site
Manager

This is unzipped into a new folder (let's say we call it "SITE_REV1"), and contains a script which invokes the following (one for each webroot):

C:\Windows\system32\inetsrv\appcmd set vdir "www.site.com/" -physicalPath:"SITE_REV1\Site"

This usually work, in 9/10 times. In some cases, the webroot seems to be updated correctly (if I inspect basic settings in IIS Manager, the path looks correct), but the running site in question is actually pointed to the old location. The only way we have managed to "fix it", is by running an IIS-reset. It isn't enough to recycle the application pool in question.

Sometimes it seems to even necessary be to make a reboot, but I'm not 100% sure that is accurate (it hasn't always been myself that was fixing the problem).

I rewrote the script using Powershell and the Web-Administration module, hoping that there was a glitch in appcmd, but the same issue occurs.

Set-ItemProperty "IIS:\Sites\www.site.com" -Name physicalPath -Value "SITE_REV1\Site"

Has anyone experienced something like this? Do anyone have a clue on what's going on, and what I can try and do to prevent this issue? Doing an IIS reset is not really a good option for us, because that would affect all sites on the server every time we try and deploy changes on a single site.

EDIT: We have identified that a start/stop of the site (NOT the application pool) in IIS Manager resolves the errorneous physical path, but if I stop the site using appcmd, change physical path, and then start it, I still suffer from the same issues. I'm at a blank…

Best Answer

Does changing the physical path from IIS Manager work correctly and immediately?

You might want to try the following command. Differently syntax, should have the same result but maybe it works slightly different internally causing IIS to pick up the changes (better):

C:\Windows\System32\inetsrv\appcmd.exe set app "www.site.com/" -[path='/'].physicalPath:"SITE_REV1\Site"