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?
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
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.
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
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" /?
Reference
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