AppCMD Quick Reference Guide for IIS 7 installed on Win2k8 Servers
What is AppCMD AppCMD is a replacement of IIS Admin Scripts (Commonly know as Vbs admin scripts for IIS) in IIS7 or Higher installed on WIn2k8 Server or higher. AppCmd.exe is the single command line tool for managing IIS 7 and above. It exposes all key server management functionality through a set of intuitive management objects that can be manipulated from the command line or from scripts.
What AppCMD is Capable of AppCmd enables you to easily control the server without using a graphical administration tool and to quickly automate server management tasks without writing code. Some of the things you can do with AppCmd: Create and configure sites, apps, application pools, and virtual directories Start and stop sites, and recycle application pools List running worker processes, and examine currently executing requests Search, manipulate, export, and import IIS and ASP.NET configuration AppCmd also allows server administrators to build advanced management tasks simply by combining multiple simpler AppCmd.exe commands, or reusing the output of the tool inside another program.
AppCMD Quick reference IIS AppCMD is very handy for deployment automation of.NET web applications. The AppCMD can be found at %systemroot%\system32\inetsrv or %systemroot%\\SysWOW64\inetsrv on web server. Please refer to IIS Administration Tools for details. The following is a quick reference for the most common usages of AppCMD in web application deployment automation.
AppCMD Quick reference 1. Add Site AppCMD add site /name:MySite /bindings: /physicalpath:”d:\MySitePath” 2. Add App Pool AppCMD add apppool /name:MyAppPool /managedRuntimeVersion:v4.0 (e.g. targeting.NET 4.0) 3. Set App Pool Credential AppCMD set config /section:applicationPools /[name='MyAppPool'].processModel.identityType:SpecificUser /[name='MyAppPool'].processModel.userName:MyDomain\MyAccou nt /[name='MyAppPool'].processModel.password:MyAccountPassword
AppCMD Quick reference 4.Add App AppCMD add app /site.name:"MySite" /path:/MyApp /physicalpath:"d:\MySitePath\MyApp" 5. Assign/Change App Pool to an App AppCMD set app "MySite/MyApp" /applicationpool:MyAppPool 6. List (App, Site, AppPool, etc.) AppCMD list app AppCMD list site AppCMD list apppool 7. Enable/Disable Anonymous Authentication (True to Enable, False to Disable) AppCMD set config "MySite/MyApp" - section:system.webServer/security/authentication/anonymousAuthen tication /enabled:"True" /commit:apphost
AppCMD Quick reference 8. Enable Windows Authentication (True to Enable, False to Disable) appcmd.exe set config "MySite/MyApp" - section:system.webServer/security/authentication/windowsAuthentic ation /enabled:"True" /commit:apphost 9. Change Windows Authentication Providers (NTLM or Negotiate) AppCMD set config MySite/MyApp - section:system.webServer/security/authentication/windowsAuthentic ation /~providers /commit:apphost (clear provider list) AppCMD set config MySite/MyApp - section:system.webServer/security/authentication/windowsAuthentic ation /-providers.[value='NTLM'] /commit:apphost (set to NTLM) AppCMD set config MySite/MyApp - section:system.webServer/security/authentication/windowsAuthentic ation /+providers.[value='Negotiate'] /commit:apphost (set to Negotiate)
AppCMD Quick reference 10. Add Custom Header – for example, nosniff header or IE 7 compatiable header AppCMD set config MySite -section:system.webServer/httpProtocol /+customHeaders.[name='X-Content-Type-Options',value='nosniff'] /commit:apphost AppCMD set config MySite -section:system.webServer/httpProtocol /+customHeaders.[name='X-UA-Compatible',value='IE=EmulateIE7'] /commit:apphost 11. Add Default Document - error if it exists already AppCMD set config "MySite/MyApp" /section:defaultDocument /+files.[value='default.asmx'] 12. Delete App and Site - error if it doesn’t exist AppCMD delete app "MySite/MyApp" AppCMD delete site "MySite"
AppCMD Quick reference 13. Delete AppPool- error if it doesn’t exist or it is used by app AppCMD delete apppool MyAppPool 14. Backup and Restore IIS Settings AppCMD add backup MyBackup AppCMD restore backup MyBackup 15. HTTPS Binding if you are using HTTP over SSL AppCMD set site /site.name:"MyApp" /+bindings.[protocol='https',bindingInformation='*:443:MySSLCertific ate']
AppCMD Quick reference How About Backup and restore option available in IIS. There are times when we IIS gets corrupted and needs to be recovered, requires a quick workaround specially in cases where availability is on high priority. Below are the steps through which IIS can be recovered in Seconds!!!
AppCMD Quick reference 1) Creating a backup :To create a backup, simply type in: >AppCmd Add Backup "BackupName" You can omit the name, in which case AppCmd is going to generate the backup name automatically using the current date and time. When a backup is created, the following happens: 1.A directory with the backup name is created under the %windir%system32inetsrvbackup directory. 2.AppCmd copies the current configuration files into the backup directory, including applicationHost.config (IIS global configuration), administration.config (Admin Tool's configuration), metabase.xml and mbschema.xml. The last two files contain the metabase data that is still used by some IIS services including SMTP and FTP, that have not been migrated to the new configuration system. AppCmd only backs up the files that are there, so if you delete any of these files, and then make a backup, the backup will not contain the missing files.
AppCMD Quick reference 2) Managing existing backups To list the backups that exist on the server, type in: >AppCmd List Backup This will list the backup objects, including their names that can be used to restore or delete them. To delete any of these backups if its no longer needed, type in: >AppCmd List Backup "BackupName" 3) Restoring a backup To restore a backup, type in: >AppCmd Restore Backup "BackupName" This will stop IIS (equivalent to calling IISRESET.EXE /STOP), and overwrite the server's state with the files in the specified backup directory. Then, IIS will be re-started (equivalent to calling IISRESET.EXE /START).