appcmd

Cannot set application pool for site in IIS via appcmd


I'm trying to set the application pool for a site via appcmd.

  1. I add a pool:

    appcmd add apppool /name:"TestAppPool" /managedPipelineMode:Classic
    
  2. I add a site:

    appcmd add site /name:"MyTestSite" /physicalPath:C:\MyTestSite
    
  3. Then I set a pool for this site:

    appcmd set site /site.name:"MyTestSite" /[path='C:\MyTestSite'].applicationPool:TestAppPool
    

    Here I get an error:

    ERROR ( message:Cannot find requested collection element. )

What's wrong here?


Solution

  • Got it working with this:

    appcmd add site /name:"MyTestSite" /bindings:"http/*:81:" /physicalPath:c:\MyTestSite
    
    appcmd set site /site.name:"MyTestSite" /[path='/'].applicationPool:TestAppPool