I need to change the physical path of a web site through the command line via the appcmd.exe tool, but I can't figure out the syntax. Can someone help?
5 Answers
This is how you should do:
C:\Windows\System32\inetsrv>appcmd set vdir "MySite/" -physicalPath:"C:\inetpub\temp"
Note: "MySite/" is a name of your virtual directory so if your virtual directory is under default web site you're likely have to set "Default Web Site/MySite/"
As for figuring out how to do other appcmd commands just type: appcmd set vdir /?
and you'll get all the info on what you can do to set your virtual directory.
Even more specifically, if you want to know what settings you can change for the specific virtual directory type:appcmd set vdir "MySite/" /?
These examples are just for virtual directory by they apply to other appcmd commands
Hope this helps

- 3,951
- 3
- 25
- 23
-
1This did not answer the question. As stated, I need to change the physical path of a web site, not a virtual directory. Also, the question was that I cannot figure out the syntax. I'm aware of /?. The help outputted with that does not clearly describe how the syntax should look. – Paul Gordon Nov 09 '09 at 21:39
-
4@Frank Edwards - 1. I assume you haven't tested my answer 2. In IIS 7.0, each *site* must have an application and each application must have a *virtual directory*. The root virtual directory of your site points to the physical path of the site. To better understand the concept of site / application / virtual directory I suggest reading this article: http://learn.iis.net/page.aspx/150/understanding-sites-applications-and-virtual-directories-in-iis-70/ especially the section with the title *IIS 7.0 Configuration:
Section* – Enes Nov 10 '09 at 06:39 -
if you create a site with appcmd add site /Name:test you will not be able to add a phyiscalPath later, you must create the site with(at least) appcmd add site /Name:test /physicalPath:"C:\inetpub\wwwroot\mysite" which results in SITE object "test" added APP object "test/" added VDIR object "test/" added which then allows you to change the vdir phyisicalPath at a later date – rob Jan 14 '13 at 09:41
-
Yeah, um, as [James notes](https://stackoverflow.com/a/7674383/1028230), @PaulGo this answer does exactly what you were asking for me as long as I run from an administrator elevated command prompt. Green check incoming! – ruffin Jul 31 '20 at 21:20
-
1@ruffin This question was posted so long ago (11 years!) that I have no clue what I was even asking or why, so I decided to just green check this answer because it seems like it's the one that's generating the most value for people... – Paul Gordon Aug 02 '20 at 23:04
The following works for me on IIS 7.5. It changes the physical path of the website:
appcmd set site /site.name:"website name" /application[path='/'].virtualDirectory[path='/'].physicalPath:"C:\new\path"
Type the following to get a complete list of properties that you can set:
appcmd set site /site.name:"website name" /?

- 262,204
- 82
- 430
- 521
And in case you are trying to change the physical path of a Web Application, here is an example changing the Web Application "Spockadoodle" that is created under Web Site "Default Web Site" to have the physical path "C:_junk".
appcmd set app /app.name:"Default Web Site/spockadoodle" -[path='/'].physicalPath:c:\_junk
I figured this out by running the command:
appcmd set app /app.name:"Default Web Site/spockadoodle" /?
and in the output I observed
ERROR (message:-path
-applicationPool
-enabledProtocols
...
-[path='string'].physicalPath
and prior to that, in the output of the command
appcmd set apps /?
the output mentioned:
Example: appcmd set app "Default Web Site/" /enabledProtocols:http
Sets the "enabledProtocols" property of the application "Default Web Site/".
So, from the example citing how to set "enabledProtocols", I substituted the example of [path='string'].physicalPath
To know the value for the attribute expression [path='string'] I observed in the output of the command
appcmd list app "Default Web Site/spockadoodle" /config
output shows that the Web App Spockadoodle has path attribtue value "/":
<application path="/spockadoodle" applicationPool="IRServices">
<virtualDirectoryDefaults />
<virtualDirectory path="/" physicalPath="c:_junk" />
</application>
Also, I figured out to use the /app.name identifier from examples on the website http://www.iis.net/learn/get-started/getting-started-with-iis/getting-started-with-appcmdexe

- 1,159
- 7
- 17
The answer above is correct. Here's what it might look like for setting the default web site and a couple of other virtual directories. We want the default web site to be on D: with a special unique path name for the app, but two of the virtual directories belong back on C: with their own paths:
C:\windows\system32\inetsrv\appcmd.exe set vdir "Default Web Site/" -physicalPath:"D:\MyUniquePath"
C:\windows\system32\inetsrv\appcmd.exe set vdir "Default Web Site/OtherWebSite" -physicalPath:"C:\OtherWeb\ApplicationServer\web"
C:\windows\system32\inetsrv\appcmd.exe set vdir "Default Web Site/ExtraPlugins" -physicalPath:"C:\OtherWeb\ApplicationServer\plugins"
The syntax is easy, but determining the exact string that appcmd takes for the virtual directory can be tricky.

- 377
- 4
- 7
To get a list of virtual directories by site and app name to help ensure you are attempting to set the right thing.
C:\Windows\System32\inetsrv\appcmd.exe list apps /config /xml
optionally pipe that |more
and/or mode con cols=160
this regex pulled out the parts I wanted
var q= from siteApp in config.XPathSelectElements("appcmd/APP")
let appName=siteApp.Attribute(XNamespace.None+"APP.NAME").Value
from app in siteApp.XPathSelectElements("application")
let appPath=app.Attribute(XNamespace.None+"path").Value
let pool=app.Attribute(XNamespace.None+"applicationPool").Value
let vd=app.XPathSelectElements("virtualDirectory[@path]")
let virtuals=vd.Select (v => new{VirDir=v.Attribute(XNamespace.None+"path").Value,PhysicalPath=v.Attribute(XNamespace.None+"physicalPath").Value})
let xvirtuals=virtuals.Select (v => new{ VirDir=v.VirDir,
PhysicalPath=v.PhysicalPath,
EnvRoot=v.PhysicalPath.ToString().StartsWith("%")})
select new{AppName=appName,AppPath=appPath, Pool=pool,Virtuals=xvirtuals};
so then for a specific site it becomes
appcmd.exe set vdir "DefaultWebSite/jms" -physicalPath:"c:\inetpub\wwwroot\mytargetPath"
here's the variable substitutions:
appcmd.exe set vdir "
+ appName + virt.VirDir + " -physicalPath:"
+ targetPath+"
and to look at the config settings for just that site:
C:\Windows\System32\inetsrv\appcmd.exe list apps /config /xml /path:/jms
another usage to be aware of:
C:\Windows\System32\inetsrv\appcmd.exe list apps /metadata /config:* /xml

- 18,464
- 20
- 106
- 193