IIS 7.0 can be installed unattended using one of 3 methods:
-Pkgmgr.exe (Works in Vista, Server 2008, and Server 2008 R2)
-Servermanagercmd.exe (Server 2008 and deprecated in Server 2008 R2) (not available in Vista or Seven)
-ServerManager PowerShell cmdlets (Server 2008 R2 ONLY!!)
In true MS form, MS has turned on the upgrade threadmill by scrapping the old sysocmgr.exe and its INF file. Now there are way more features to pick from than IIS 6.0 but NNTP is dropped and the SMTP is now separated from IIS and is now listed as a *feature* in Windows 2008's Server Manager.
Other changes are explained here:
http://blogs.technet.com/mscom/archive/2007/09/07/the-tasty-morsels-found-in-dogfood-mscom-ops-top-10-changes-in-iis7-0.aspx
In either method, you can no longer specify where the files are to be installed at the onset. This is confirmed with the existence of a batch file to move ISS to another drive written by an IIS team member! Another thing that could be done is to format a new partition and instead of assigning it a drive letter, use the "mount in the following empty NTFS folder" option in disk management to host C:\inetpub before the install. With the lack of ability to specify where to install ANY Service or Feature with the any of the 3 methods, it's as if MS is hinting that UNIX's way of partitions instead of drive letters is the way to go!
All 3 methods share the same key words for installing Roles, Role Services and Features. The following methods work "as-is" on Server 2008 R1 except for PowerShell method which is Server 2008 R2 only. The names of the Roles, Role Services and Features have slightly changed from R1 to R2.
**************
The Pkgmgr.exe method is the simplest but you cannot install SMTP.
It is explained here http://learn.iis.net/page.aspx/133/using-unattend-setup-to-install-iis-7/
And http://learn.iis.net/page.aspx/132/install-iis-7-from-the-command-line/
NOTE: It's very important that the Windows build version within the xml file (version="6.0.6001.16659") is the full version number of the OS, otherwise the xml file won't work.
You can use the following to install ALL of IIS' 7.0 features:
-Create unattend.xml from:
And then launch with: start /w pkgmgr /n:unattend.xml
You can also skip the XML file creation with this one liner:
start /w pkgmgr /l:log.etw /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ASP;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-Security;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-RequestFiltering;IIS-IPSecurity;IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI
Now this will install IIS but ONLY on the %SystemDrive% ( C:\ drive).
See the batch file in the next section on how to move it to another drive letter.
******************
The Servermanagercmd.exe will not work in a workstation OS (Vista or Seven) but will be able to install SMTP and any other Features/server Roles you wish at the same time as IIS 7.0. The catch is that MS has deprecated (aka "to be phased out later") in Windows server 2008 R2.
Every time you launch it or its GUI counterpart it updates a log in: C:\windows\LOGS\ServerManager.log
The hardest thing to figure out is the difference between a Role, Role Services and Features.
A Role is a grouping of Role Services. Features are basically Services that have not been grouped under a Role. Role Services can also be part of other Roles. If you specify to install a Role (e.g. Web-Server for IIS 7), its default Role Services will be installed. You can get a full list here: http://technet.microsoft.com/en-us/library/cc875805(WS.10).aspx (Well, at least it was here Aug 28, 2009) but notice they don't tell you which is the "Role" and which is the "Role Service". Since it’s Trial and Error, use the -whatif parameter. You can also get a hint as what is a Role Service by running: ServerManagerCmd.exe -query
Notice that Sub-Roles also exists (e.g. Web-App-Development)
This will install IIS 7.0 (aka the Web-Server "role") without SMTP:
ServerManagerCmd.exe -install Web-Server -allSubFeatures -resultPath C:\TEMP\WebServer.xml -restart
To install IIS 7.0 with default "role services" plus the SMTP "Feature", create IIS7_w_SMTP.xml with the following:
<ServerManagerConfiguration Action="Install" xmlns="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">
<Role Id="Web-Server"/>
<Feature Id="SMTP-Server"/>
</ServerManagerConfiguration>
Then launch:
ServerManagerCmd.exe -inputPath .\IIS7_w_SMTP.xml -resultPath .\IIS7_Log_file.xml
Other things to remember:
-If you want to install IIS with your selection of Role Services, don't mention the Web-Server Role or Sub-Roles, just the "Role Services" themselves.
-You cannot have comments in the xml file (e.g. - <!-- ====== --> ) in R1. They are, however, allowed in R2. (Go figure!)
Now this will install IIS but ONLY on the %SystemDrive% ( C:\ drive).
http://blogs.iis.net/thomad/archive/2008/02/10/moving-the-iis7-inetpub-directory-to-a-different-drive.aspx
Here, Thomas Deml, an ISS team member shares a script to move the IIS INETPUB folder *after* it is installed. What follows is that script (with a bug fix) since MS' web sites are made of vapour and disappears on a whim:
<< Start of moveiis7root.bat >>
@echo off
IF "%1" == "" goto err
setlocal
set MOVETO=%1:\
REM simple error handling if drive does not exist or argument is wrong
IF NOT EXIST %MOVETO% goto err
REM Backup IIS config before we start changing config to point to the new path
%windir%\system32\inetsrv\appcmd add backup beforeRootMove
REM Stop all IIS services
iisreset /stop
REM Copy all content
REM /O - copy ACLs
REM /E - copy sub directories including empty ones
REM /I - assume destination is a directory
REM /Q - quiet
REM echo on, because user will be prompted if content already exists.
echo on
xcopy %systemdrive%\inetpub %MOVETO%inetpub /O /E /I /Q
@echo off
REM Move AppPool isolation directory
reg add HKLM\System\CurrentControlSet\Services\WAS\Parameters /v ConfigIsolationPath /t REG_SZ /d %MOVETO%inetpub\temp\appPools /f
REM Move logfile directories
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.traceFailedRequestsLogging.directory:"%MOVETO%inetpub\logs\FailedReqLogFiles"
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.logfile.directory:"%MOVETO%inetpub\logs\logfiles"
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralBinaryLogFile.directory:"%MOVETO%inetpub\logs\logfiles"
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralW3CLogFile.directory:"%MOVETO%inetpub\logs\logfiles"
REM Move config history location, temporary files, the path for the Default Web Site and the custom error locations
%windir%\system32\inetsrv\appcmd set config -section:system.applicationhost/configHistory -path:%MOVETO%inetpub\history
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/asp -cache.disktemplateCacheDirectory:"%MOVETO%inetpub\temp\ASP Compiled Templates"
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression -directory:"%MOVETO%inetpub\temp\IIS Temporary Compressed Files"
%windir%\system32\inetsrv\appcmd set vdir "Default Web Site/" -physicalPath:%MOVETO%inetpub\wwwroot
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='401'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='403'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='404'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='405'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='406'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='412'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='500'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='501'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='502'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
REM Make sure Service Pack and Hotfix Installers know where the IIS root directories are
reg add HKLM\Software\Microsoft\inetstp /v PathWWWRoot /t REG_SZ /d %moveto%inetpub\wwwroot /f
reg add HKLM\Software\Microsoft\inetstp /v PathFTPRoot /t REG_SZ /d %moveto%inetpub\ftproot /f
REM Restart all IIS services
iisreset /start
echo.
echo.
echo ===============================================================================
echo Moved IIS7 root directory from %systemdrive%\ to %MOVETO%.
echo.
echo Please verify if the move worked. If so you can delete the %systemdrive%\inetpub directory.
echo If something went wrong you can restore the old settings via
echo "APPCMD restore backup beforeRootMove"
echo and
echo "REG delete HKLM\System\CurrentControlSet\Services\WAS\Parameters\ConfigIsolationPath"
echo You also have to reset the PathWWWRoot and PathFTPRoot registry values
echo in HKEY_LOCAL_MACHINE\Software\Microsoft\InetStp.
echo ===============================================================================
echo.
echo.
endlocal
goto success
REM error message if no argument or drive does not exist
:err
echo.
echo New root drive letter required.
echo Here an example how to move the IIS root to the F:\ drive:
echo.
echo MOVEIISROOT.BAT F
echo.
echo.
:success
<< End of moveiis7root.bat >>
AppCMD.exe can be used to tweak some more after the install is completed but I digress.
http://blogs.iis.net/webdevelopertips/archive/2009/01/11/tip-42-did-you-know-configurationeditor-allows-you-to-generate-c-javascript-or-appcmd-script-to-update-configuration.aspx
**************
If you have the RTM version of Windows Server 2008 R2 then you can also use PowerShell.
To launch PowerShell 2.0 from the command-line type: POWERSHELL
* Import the Server Manager Module with: Import-Module ServerManager
* You will get the following cmdlets to list/add/remove features and roles:
Get-WindowsFeature --> lists available/Installed features and roles
Add-WindowsFeature --> installs a feature or role
Remove-WindowsFeature --> removes a feature or role
The rest is poorly documented right now but it seems to borrow heavily from the 2 previous methods.
At this time, there is no PowerShell script to install IIS 7.0 so here is the one I wrote:
# Installs IIS 7.0 with ALL Role-Services Plus SMTP feature
# Creates a log file in the same folder as this script
# CAVEAT: This *ONLY* works on Windows server 2008 R2 (and later?)
#
#
# To Run this Powershell script
# Step 1: Allow Powershell scripts to run
# Start -> Run
# Type: PowerShell <Press Enter>
# Type: Set-ExecutionPolicy Unrestricted <Press Enter>
# Type: <Press Enter>
#
# Step 2: Run this Powershell Script
# From the PowerShell Prompt
# Browse to the folder where this Powershell Script is located
# Type: . <name of this Script>
# OR
#
# Right-click on the Powershell Script file (*.ps1)
# Select "Run with PowerShell"
#
# Powershell Tip: Do not point Add-WindowsFeature's -logPath and redirection (>> $LogFile) to the same file
# Powershell gets confused as to what encoding to use (ANSI/UTF-8) and you will get Chinese characters!?!
# Use "transcript" instead as done below.
# NOTE: for some reasons it talks about "activities not shown..."
#
#Make $LogFile match the Powershell script name with a date and time stamp followed by ".log"
$dt = Get-Date -format "yyyyMMdd_hhmm"
$LogFile = ($MyInvocation.MyCommand.Name).Replace(".ps1","_$dt.log")
start-transcript $LogFile #start the transcript (aka Logging)
trap { stop-transcript; break} #error trapping code to stop the transcript and break out of script
#(alternatively could use "continue" execution)
stop-transcript #stop the transcript (aka Logging)
#pause 50 Seconds (There is no "PAUSE" in PS, thx MS!)
Start-sleep -s 50
You are still able to use AppCMD.exe to tweak after install (e.g. the batch file to move c:\ inetpub) but it is rumoured that it will also be assimilated into a PowerSmell module.
IIS 7.0 can be installed unattended using one of 3 methods:
-Pkgmgr.exe (Works in Vista, Server 2008, and Server 2008 R2)
-Servermanagercmd.exe (Server 2008 and deprecated in Server 2008 R2) (not available in Vista or Seven)
-ServerManager PowerShell cmdlets (Server 2008 R2 ONLY!!)
In true MS form, MS has turned on the upgrade threadmill by scrapping the old sysocmgr.exe and its INF file. Now there are way more features to pick from than IIS 6.0 but NNTP is dropped and the SMTP is now separated from IIS and is now listed as a *feature* in Windows 2008's Server Manager.
Other changes are explained here:
http://blogs.technet.com/mscom/archive/2007/09/07/the-tasty-morsels-found-in-dogfood-mscom-ops-top-10-changes-in-iis7-0.aspx
In either method, you can no longer specify where the files are to be installed at the onset. This is confirmed with the existence of a batch file to move ISS to another drive written by an IIS team member! Another thing that could be done is to format a new partition and instead of assigning it a drive letter, use the "mount in the following empty NTFS folder" option in disk management to host C:\inetpub before the install. With the lack of ability to specify where to install ANY Service or Feature with the any of the 3 methods, it's as if MS is hinting that UNIX's way of partitions instead of drive letters is the way to go!
All 3 methods share the same key words for installing Roles, Role Services and Features. The following methods work "as-is" on Server 2008 R1 except for PowerShell method which is Server 2008 R2 only. The names of the Roles, Role Services and Features have slightly changed from R1 to R2.
**************
The Pkgmgr.exe method is the simplest but you cannot install SMTP.
It is explained here http://learn.iis.net/page.aspx/133/using-unattend-setup-to-install-iis-7/
And http://learn.iis.net/page.aspx/132/install-iis-7-from-the-command-line/
NOTE: It's very important that the Windows build version within the xml file (version="6.0.6001.16659") is the full version number of the OS, otherwise the xml file won't work.
You can use the following to install ALL of IIS' 7.0 features:
-Create unattend.xml from:
And then launch with: start /w pkgmgr /n:unattend.xml
You can also skip the XML file creation with this one liner:
start /w pkgmgr /l:log.etw /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ASP;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-Security;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-RequestFiltering;IIS-IPSecurity;IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI
Now this will install IIS but ONLY on the %SystemDrive% ( C:\ drive).
See the batch file in the next section on how to move it to another drive letter.
******************
The Servermanagercmd.exe will not work in a workstation OS (Vista or Seven) but will be able to install SMTP and any other Features/server Roles you wish at the same time as IIS 7.0. The catch is that MS has deprecated (aka "to be phased out later") in Windows server 2008 R2.
Every time you launch it or its GUI counterpart it updates a log in: C:\windows\LOGS\ServerManager.log
The hardest thing to figure out is the difference between a Role, Role Services and Features.
A Role is a grouping of Role Services. Features are basically Services that have not been grouped under a Role. Role Services can also be part of other Roles. If you specify to install a Role (e.g. Web-Server for IIS 7), its default Role Services will be installed. You can get a full list here: http://technet.microsoft.com/en-us/library/cc875805(WS.10).aspx (Well, at least it was here Aug 28, 2009) but notice they don't tell you which is the "Role" and which is the "Role Service". Since itâs Trial and Error, use the -whatif parameter. You can also get a hint as what is a Role Service by running: ServerManagerCmd.exe -query
Notice that Sub-Roles also exists (e.g. Web-App-Development)
This will install IIS 7.0 (aka the Web-Server "role") without SMTP:
ServerManagerCmd.exe -install Web-Server -allSubFeatures -resultPath C:\TEMP\WebServer.xml -restart
To install IIS 7.0 with default "role services" plus the SMTP "Feature", create IIS7_w_SMTP.xml with the following:
<ServerManagerConfiguration Action="Install" xmlns="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">
<Role Id="Web-Server"/>
<Feature Id="SMTP-Server"/>
</ServerManagerConfiguration>
Then launch:
ServerManagerCmd.exe -inputPath .\IIS7_w_SMTP.xml -resultPath .\IIS7_Log_file.xml
Other things to remember:
-If you want to install IIS with your selection of Role Services, don't mention the Web-Server Role or Sub-Roles, just the "Role Services" themselves.
-You cannot have comments in the xml file (e.g. - <!-- ====== --> ) in R1. They are, however, allowed in R2. (Go figure!)
Now this will install IIS but ONLY on the %SystemDrive% ( C:\ drive).
http://blogs.iis.net/thomad/archive/2008/02/10/moving-the-iis7-inetpub-directory-to-a-different-drive.aspx
Here, Thomas Deml, an ISS team member shares a script to move the IIS INETPUB folder *after* it is installed. What follows is that script (with a bug fix) since MS' web sites are made of vapour and disappears on a whim:
<< Start of moveiis7root.bat >>
@echo off
IF "%1" == "" goto err
setlocal
set MOVETO=%1:\
REM simple error handling if drive does not exist or argument is wrong
IF NOT EXIST %MOVETO% goto err
REM Backup IIS config before we start changing config to point to the new path
%windir%\system32\inetsrv\appcmd add backup beforeRootMove
REM Stop all IIS services
iisreset /stop
REM Copy all content
REM /O - copy ACLs
REM /E - copy sub directories including empty ones
REM /I - assume destination is a directory
REM /Q - quiet
REM echo on, because user will be prompted if content already exists.
echo on
xcopy %systemdrive%\inetpub %MOVETO%inetpub /O /E /I /Q
@echo off
REM Move AppPool isolation directory
reg add HKLM\System\CurrentControlSet\Services\WAS\Parameters /v ConfigIsolationPath /t REG_SZ /d %MOVETO%inetpub\temp\appPools /f
REM Move logfile directories
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.traceFailedRequestsLogging.directory:"%MOVETO%inetpub\logs\FailedReqLogFiles"
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.logfile.directory:"%MOVETO%inetpub\logs\logfiles"
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralBinaryLogFile.directory:"%MOVETO%inetpub\logs\logfiles"
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralW3CLogFile.directory:"%MOVETO%inetpub\logs\logfiles"
REM Move config history location, temporary files, the path for the Default Web Site and the custom error locations
%windir%\system32\inetsrv\appcmd set config -section:system.applicationhost/configHistory -path:%MOVETO%inetpub\history
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/asp -cache.disktemplateCacheDirectory:"%MOVETO%inetpub\temp\ASP Compiled Templates"
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression -directory:"%MOVETO%inetpub\temp\IIS Temporary Compressed Files"
%windir%\system32\inetsrv\appcmd set vdir "Default Web Site/" -physicalPath:%MOVETO%inetpub\wwwroot
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='401'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='403'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='404'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='405'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='406'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='412'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='500'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='501'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
%windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='502'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
REM Make sure Service Pack and Hotfix Installers know where the IIS root directories are
reg add HKLM\Software\Microsoft\inetstp /v PathWWWRoot /t REG_SZ /d %moveto%inetpub\wwwroot /f
reg add HKLM\Software\Microsoft\inetstp /v PathFTPRoot /t REG_SZ /d %moveto%inetpub\ftproot /f
REM Restart all IIS services
iisreset /start
echo.
echo.
echo ===============================================================================
echo Moved IIS7 root directory from %systemdrive%\ to %MOVETO%.
echo.
echo Please verify if the move worked. If so you can delete the %systemdrive%\inetpub directory.
echo If something went wrong you can restore the old settings via
echo "APPCMD restore backup beforeRootMove"
echo and
echo "REG delete HKLM\System\CurrentControlSet\Services\WAS\Parameters\ConfigIsolationPath"
echo You also have to reset the PathWWWRoot and PathFTPRoot registry values
echo in HKEY_LOCAL_MACHINE\Software\Microsoft\InetStp.
echo ===============================================================================
echo.
echo.
endlocal
goto success
REM error message if no argument or drive does not exist
:err
echo.
echo New root drive letter required.
echo Here an example how to move the IIS root to the F:\ drive:
echo.
echo MOVEIISROOT.BAT F
echo.
echo.
:success
<< End of moveiis7root.bat >>
AppCMD.exe can be used to tweak some more after the install is completed but I digress.
http://blogs.iis.net/webdevelopertips/archive/2009/01/11/tip-42-did-you-know-configurationeditor-allows-you-to-generate-c-javascript-or-appcmd-script-to-update-configuration.aspx
**************
If you have the RTM version of Windows Server 2008 R2 then you can also use PowerShell.
To launch PowerShell 2.0 from the command-line type: POWERSHELL
* Import the Server Manager Module with: Import-Module ServerManager
* You will get the following cmdlets to list/add/remove features and roles:
Get-WindowsFeature --> lists available/Installed features and roles
Add-WindowsFeature --> installs a feature or role
Remove-WindowsFeature --> removes a feature or role
The rest is poorly documented right now but it seems to borrow heavily from the 2 previous methods.
At this time, there is no PowerShell script to install IIS 7.0 so here is the one I wrote:
# Installs IIS 7.0 with ALL Role-Services Plus SMTP feature
# Creates a log file in the same folder as this script
# CAVEAT: This *ONLY* works on Windows server 2008 R2 (and later?)
#
#
# To Run this Powershell script
# Step 1: Allow Powershell scripts to run
# Start -> Run
# Type: PowerShell <Press Enter>
# Type: Set-ExecutionPolicy Unrestricted <Press Enter>
# Type: <Press Enter>
#
# Step 2: Run this Powershell Script
# From the PowerShell Prompt
# Browse to the folder where this Powershell Script is located
# Type: . <name of this Script>
# OR
#
# Right-click on the Powershell Script file (*.ps1)
# Select "Run with PowerShell"
#
# Powershell Tip: Do not point Add-WindowsFeature's -logPath and redirection (>> $LogFile) to the same file
# Powershell gets confused as to what encoding to use (ANSI/UTF-8) and you will get Chinese characters!?!
# Use "transcript" instead as done below.
# NOTE: for some reasons it talks about "activities not shown..."
#
#Make $LogFile match the Powershell script name with a date and time stamp followed by ".log"
$dt = Get-Date -format "yyyyMMdd_hhmm"
$LogFile = ($MyInvocation.MyCommand.Name).Replace(".ps1","_$dt.log")
start-transcript $LogFile #start the transcript (aka Logging)
trap { stop-transcript; break} #error trapping code to stop the transcript and break out of script
#(alternatively could use "continue" execution)
stop-transcript #stop the transcript (aka Logging)
#pause 50 Seconds (There is no "PAUSE" in PS, thx MS!)
Start-sleep -s 50
You are still able to use AppCMD.exe to tweak after install (e.g. the batch file to move c:\ inetpub) but it is rumoured that it will also be assimilated into a PowerSmell module.
The following is the Move_IIS7.bat (moveiis7root.zip) translated to PowerShell.
>>> Use at your own risk. <<<
# REM The following it the CMD created by Thomas Deml, an ISS team member
#http://blogs.iis.net/thomad/archive/2008/02/10/moving-the-iis7-inetpub-directory-to-a-different-drive.aspx
# now translated to Powershell by misterd (Ottawa, Canada)
#Pickup Drive letter from command line
$MOVETO=$arg:
Write-host $MOVETO
#REM simple error handling if drive does not exist or argument is wrong
if (-not (test-path $MOVETO)){
echo $MOVETO + " drive does not exist"
EXIT 2
}
Write-host
Write-host *****************************************
Write-host Moving C:\inetpub\ to ${MOVETO}inetpubWrite-host *****************************************
Write-host
Write-host REM Backup IIS config before we start changing config to point to the new path
& $env:WINDIR\system32\inetsrv\appcmd add backup beforeRootMove
Write-host Stop all IIS services
iisreset /stop
#REM Copy all content
#REM /O - copy ACLs
#REM /E - copy sub directories including empty ones
#REM /I - assume destination is a directory
#REM /Q - quiet
#CAVEAT: the following does not show up in log files
Write-host REM Xcopy $env:systemdrive\inetpub to ${MOVETO}inetpub folder
xcopy $env:systemdrive\inetpub ${MOVETO}inetpub /O /E /I /Q
Write-host REM Move logfile directories
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:system.applicationHost/sites" "-siteDefaults.traceFailedRequestsLogging.directory: ""${MOVETO}inetpub\logs\FailedReqLogFiles"""
& $env:windir\system32\inetsrv\appcmd set config "-section:system.applicationHost/sites" "-siteDefaults.logfile.directory:""${MOVETO}inetpub\logs\FailedReqLogFiles"""
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:system.applicationHost/log" "-centralBinaryLogFile.directory:""${MOVETO}inetpub\logs\logfiles"""
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:system.applicationHost/log" "-centralW3CLogFile.directory:""${MOVETO}inetpub\logs\logfiles"""
Write-host REM Move config history location
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:system.applicationhost/configHistory" "-path:${MOVETO}inetpub\history"
Write-host REM Move temporary files location
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:system.webServer/asp" "-cache.disktemplateCacheDirectory:${MOVETO}inetpub\temp\ASP Compiled Templates"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:system.webServer/httpCompression" "-directory:${MOVETO}inetpub\temp\IIS Temporary Compressed Files"
Write-host REM Move the path for the Default Web Site location
& $env:WINDIR\system32\inetsrv\appcmd set vdir "Default Web Site/" "-physicalPath:${MOVETO}inetpub\wwwroot"
Write-host REM Move the path for the custom error locations
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='401'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='403'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='404'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='405'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='406'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='412'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='500'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='501'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
& $env:WINDIR\system32\inetsrv\appcmd set config "-section:httpErrors" "/[statusCode='502'].prefixLanguageFilePath:${MOVETO}inetpub\custerr"
Write-host REM Make sure Service Pack and Hotfix Installers know where the IIS root directories are
reg add HKLM\Software\Microsoft\inetstp /v PathWWWRoot /t REG_SZ /d ${MOVETO}inetpub\wwwroot /f
reg add HKLM\Software\Microsoft\inetstp /v PathFTPRoot /t REG_SZ /d ${MOVETO}inetpub\ftproot /f
Write-host REM Restart all IIS services
iisreset /start
Write-host
Write-host ===============================================================================
Write-host Moved IIS7 root directory from $env:{systemdrive}\ to ${MOVETO}\.
Write-host
Write-host Please verify if the move worked. If so you can delete the $env:{systemdrive}\inetpub directory.
Write-host If something went wrong you can restore the old settings via
Write-host "APPCMD restore backup beforeRootMove"
Write-host and
Write-host "REG delete HKLM\System\CurrentControlSet\Services\WAS\Parameters\ConfigIsolationPath"
Write-host You also have to reset the PathWWWRoot and PathFTPRoot registry values
Write-host in HKEY_LOCAL_MACHINE\Software\Microsoft\InetStp.
Write-host ===============================================================================
Write-host
read-host 'Press ENTER key to continue...' # aka Pause
Reviews related to Microsoft Internet Information Server (IIS)
This website uses cookies.
By continuing to use this site and/or clicking the "Accept" button you are providing consent
Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our
websites or when you do business with us. For more information about our
Privacy Policy and our data protection
efforts, please visit
GDPR-HQ