4

I'm using appcmd to create a new virtual directory in IIS8. The syntax for this is:

appcmd add vdir /app.name:<NAME> /path:<PATH> /physicalPath:<PHYSICAL-PATH>

This works fine. Now I need to set some credentials; this is easy in the GUI (virtual dir > basic settings > connect as). When I set this, I can see in my applicationHost.config file that it is updating an XML entry. So I should be able to set that manually with appcmd. I'm struggling with the syntax to navigate to the right XML element so I can set the attribute userName and add the attribute password.

Here is my XML:

<sites>
  <site name="EXAMPLESITE" id="4">
    <application path="/" applicationPool="EXAMPLEPOOL">
        <virtualDirectory path="/" physicalPath="c:\wwwroot\" userName="" />
        <virtualDirectory path="/upload" physicalPath="\\SOME-COMPUTER-ON-NETWORK\upload" userName="" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:80" />
    </bindings>
  </site>
</sites>
Michael
  • 8,362
  • 6
  • 61
  • 88
Olle
  • 201
  • 6
  • 17

1 Answers1

9

This should work:

appcmd set vdir /vdir.name:"EXAMPLESITE/upload" /userName:user /password:password
Ross Presser
  • 6,027
  • 1
  • 34
  • 66
Kev
  • 118,037
  • 53
  • 300
  • 385
  • Work fine! Thanks @Kev I just managed to get it to work with the following syntax as well. But your solution is much cleaner. _appcmd.exe set config -section:system.applicationHost/sites "/[name='EXAMPLESITE'].[path='/'].[path='/upload'].userName:" "/[name='EXAMPLESITE'].[path='/'].[path='/upload'].password:" /commit:apphost_ – Olle Sep 20 '13 at 09:32
  • @Olle excellent. Yeah, there are quite a few ways to do the same thing with appcmd. Glad I could help. – Kev Sep 20 '13 at 09:36
  • It also works for IIS Express, but `/apphostconfig` might be required there. – Lex Li Oct 05 '19 at 19:54