How to Create a WebSite/AppPool in IIS using Command
Abstract: \sites\example.com. appcmd add site /nameChange App Pool of Website You can also change the Application Pool of any website using appcmd command. Use
IIS (Internet Information Services) is a web server created by Microsoft for Windows systems. As a system administrator, we know that to manage IIS is easy from GUI. Some times we get tasks to create a large number of websites under IIS or create a site in IIS using windows batch script. This article will guide you on how to create a Website, Application, site binding, and Application Pools in IIS using the command line.
Before using the below commands, start the command prompt as administrator. So that you can get all the privileges to make changes. After that navigate to C:\Windows\System32\inetsrv directory.
cd c:\Windows\System32\inetsrvCreate Website in IIS
For example we need to create a website named example.com with document root c:\sites\example.com.
appcmd add site /name:example.com /id:1 /physicalPath:c:\sites\example.com /bindings:http/*:80:example.comCreate Subdirectory Application
You can add a subdirectory application to your existing website. For example, to configure URL like http://example.com/blog, the /blog is the subdirectory application configured under example.com website. To create this create execute the following command. Assuming the document root for blog is c:\sites\blog.
appcmd add app /site.name:example.com /path:/blog /physicalPath:c:\sites\blogCreate Application Pool in IIS
IIS App Pool used for grouping of sites to use similar configuration settings or prevent other applications to use resources of one application by other applications. Use one of below option as per your requirements
App Pool with Default SettingsUse the following command to create Application Pool named 「myAppPool」 with default settings of IIS.
appcmd add apppool /name:myAppPoolApp Pool with Specific Settings
If you want to use different settings for your App Pools, use command like below. Change managedRuntimeVersion as per your requirements v1.0, v1.1, v2.0 or v4.0.
appcmd add apppool /name:myAppPool /managedRuntimeVersion:v2.0 /managedPipelineMode:Integrated appcmd add apppool /name:myAppPool /managedRuntimeVersion:v2.0 /managedPipelineMode:ClassicChange App Pool of Website
You can also change the Application Pool of any website using appcmd command. Use following command to change application pool of site example.com and set App Pool to myAppPool
appcmd set site /site.name:example.com /[path='/'].applicationPool:myAppPool
To change the Application Pool for a subdirectory URL use the following command.
appcmd set site /site.name:example.com /[path='/blog'].applicationPool:myAppPoolConclusion
You can perform any tasks related to IIS using appcmd command-line utility. This allows your to quick website configuration, easy backup and restore.