Jeff Gilbert's Web blog at myITforum.com

This posting is provided "AS IS" with no warranties, and confers no rights :-)
Automating IIS 7 Installation to Support Configuration Manager 2007

If you've ever installed, or even thought about installing, a Configuration Manager site, or site system requiring IIS on a Windows Server 2008 computer then you've probably had a look at the How to Configure Windows Server 2008 for Site Systems help topic in the Configuration Manager 2007 Documentation Library and then spent some time installing and manually configuring IIS 7, then installing WebDAV for IIS 7, and then spent some more time configuring WebDAV afterwards. If you only have to do this one or two times it's not too big of a deal, but because I'm constantly installing Configuration Manager lab machines on Windows Server 2008, going through the motions of installing and configuring IIS 7 can get repetitive. Not to mention that I always seem to leave out a bit of the configuration that sends me back to installing a missing feature later. After about the thousandth time configuring IIS 7 manually, I thought to myself "there's got to be a way to script this and save some time". If you've had the same thought then this post is for you. After some looking around, I couldn't find the steps to install and configure IIS 7 to support Configuration Manager installations anywhere so I decided to just figure it out for myself (and consequently, for you as well Smile).

My first stop was figuring out how to install IIS 7 via the command line. Instead of using sysocmgr (used to install IIS 6), Windows Server 2008 has a handy server manager command-line tool that is used to install Windows Server 2008 roles and features (could be any role or feature you want and not just IIS btw). If you want to install a single role or feature then you can just use the command line, but when you need to install multiple roles or features, you have to create an .xml answer file. Sounds a little daunting, but it's really not too bad. I just used notepad to create an answer file using these instructions. I covered all of the requirements defined in the Windows Server 2008 How To topic in the documentation library for every possible requirement other than the last bit about modifying the requestFiltering section on BITS-enabled distribution point computers. Here's what I came up with:

<ServerManagerConfiguration
Action="Install"
xmlns="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1"> 
    <Role Id="Web-Server"/> 
    <RoleService Id="Web-Asp-Net"/> 
    <RoleService Id="Web-ASP"/> 
    <RoleService Id="Web-Windows-Auth"/> 
    <RoleService Id="Web-Metabase"/> 
    <RoleService Id="Web-WMI"/> 
    <Feature Id="BITS"/> 
    <Feature Id="RDC"/>
</ServerManagerConfiguration>

To kick off the IIS installation using just the answer file, open a command prompt (right-click command prompt and select run as administrator) and then enter a command in the format below. I saved the log file as a .log instead of a .txt so I could use SMS Trace to watch the IIS installation action progress in the log instead of the counter in the command shell window, but you don't have to):

ServerManagerCmd.exe -inputPath <answer.xml [-logPath <log.txt>]

After running that command, you should see something similar to this:

Installing IIS 7 

Moving along to WebDAV which I thought was going to be a bit more of a challenge. Not only do you need to install the applicable version of WebDAV (either x86 or x64), you also need to create an authoring rule and configure other settings post installation. Luckily, another tool came to my rescue: appcmd.exe. This tool allows you to configure IIS 7 settings from the command-line…handy.

Armed with an IIS 7 installation answer file and the servermanagercmd and appcmd tools, I was ready to write the script to automate the process. I also wanted the script to auto-generate the IIS 7 answer .xml file for me so I wouldn't have to carry around an extra file everywhere (those .xml files can get heavy and I'm not as young as I used to be). Before I get to the script though, here are some caveats if you're planning on using my script 'as is':

  • The script relies on having the applicable WebDAV installation .msi in the same directory that the script is started from (in my testing I put the script at the root of C:\ and used the x86 version)
  • The script assumes that everything is installed on the C:\ so if you're using a different drive you'll need to tweak the script as necessary
  • There is no error checking in the script as I am only planning on using this in my lab for clean installations
  • You can't use this script if you've already installed IIS 7 as it will fail to reconfigure IIS
  • This script is provided 'as is', your mileage may vary, test it in a lab to ensure it does everything you need it to before using it in production, etc...  

So without much futher adieu, here's the PowerShell script…what? Don't have powershell installed on your Windows Server 2008 computer? No problem, just do this, open a command prompt (run as administrator) and run: ServerManagerCmd –install powershell and then continue after PowerShell installs. To run the .ps1 you'll also need to relax the PowerShell script execution policy since this script won't be signed. To do that, open up PowerShell and run Set-ExecutionPolicy Unrestricted. This setting will allow you to run unsigned scripts, but will also lower security for running scripts unless you change the security setting to a higher level later.

OK, moving on, here come the scripts. I've shown how to do this using PowerShell, .vbs, and .bat, but I do not recommend C&P'ing these scripts as who knows what word-wrap as done to them. If you want to use these scripts, you should probably download the .zip containing all of them from here. The .zip contains the un-commented PowerShell (IIS7.ps1), visual basic script (IIS7.vbs), and a batch file (IIS7.bat) that all do the same thing except that you have to manually create the answer.xml file yourself when using the .bat.

Here's the PowerShell version. I've inserted comments in this post to tell you what is going on as the script progresses:

# All the write-output stuff is just to make the console output look nice
write-output ""
write-output "Creating IIS answer file"
# The next line creates the IIS 7 answer file named answer.xml located at the root of C:\ (where the script was started from). Out-null is my attempt to make PowerShell wait before moving on until this process completes
new-item -path C:\ -name answer.xml -type 'file' | out-null
# These add-content lines are used by PowerShell to write the answer.xml file with the required role and role services Id's
add-content -path answer.xml -value '<ServerManagerConfiguration'
add-content -path answer.xml -value 'Action="Install"'
add-content -path answer.xml -value 'xmlns="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">'
add-content -path answer.xml -value '    <Role Id="Web-Server"/>'
add-content -path answer.xml -value '    <RoleService Id="Web-Asp-Net"/>'
add-content -path answer.xml -value '    <RoleService Id="Web-ASP"/>'
add-content -path answer.xml -value '    <RoleService Id="Web-Windows-Auth"/>'
add-content -path answer.xml -value '    <RoleService Id="Web-Metabase"/>'
add-content -path answer.xml -value '    <RoleService Id="Web-WMI"/>'
add-content -path answer.xml -value '    <Feature Id="BITS"/>'
add-content -path answer.xml -value '    <Feature Id="RDC"/>'
add-content -path answer.xml -value '</ServerManagerConfiguration>'
write-output ""
# Here are the commands that write the script's progress to the command shell, use the newly created answer.xml file to install IIS 7, and write installation progress to c:\iisinstall.log
write-output "Installing IIS 7"
ServerManagerCmd.exe -inputPath c:\answer.xml -logPath c:\IISInstall.log | out-null
# This line just deletes the answer.xml file after ServerManagerCmd has finished with it
remove-item c:\answer.xml
write-output ""
# These lines write the script's progress to the command shell and run the applicable WebDAV installation command line
write-output "Installing WebDAV for IIS 7"
msiexec /i webdav_x86_rtw.msi /qn | out-null
write-output ""
# These lines write the script's progress to the command shell and use appcmd.exe to enable WebDAV
write-output "Enabling WebDAV"
c:\windows\system32\inetsrv\AppCmd.exe set config "Default Web Site/" /section:system.webServer/webdav/authoring /enabled:true /commit:apphost | out-null
write-output ""
# These lines write the script's progress to the command shell and use appcmd.exe to create and configure the required WebDAV authoring rule
write-output "Creating and configuring a WebDAV authoring rule"
c:\windows\system32\inetsrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoringRules /"+[users='*',path='*',access='Read']" /commit:apphost | out-null
write-output ""
# These lines write the script's progress to the command shell and use appcmd.exe to configure the remaining required WebDAV properties
write-output "Configuring WebDAV"
write-output ""
write-output "    Allowing access to hidden files"
c:\windows\system32\inetsrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /fileSystem.allowHiddenFiles:true /commit:apphost | out-null
write-output "    Allowing anonymous property queries"
c:\windows\system32\inetsrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowAnonymousPropfind:true /commit:apphost | out-null
write-output "    Not allowing Custom properties"
c:\windows\system32\inetsrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowCustomProperties:false /commit:apphost | out-null
write-output "    Allowing property queries with infinite depth"
c:\windows\system32\inetsrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowInfinitePropfindDepth:true /commit:apphost | out-null
write-output "    Allowing hidden files to be listed"
c:\windows\system32\inetsrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /fileSystem.allowHiddenFiles:true /commit:apphost | out-null
write-output ""
write-output ""
# These lines aren't really necessary, but I like the script to pause so I can ensure that it finished. It's also a cool reminder of how to do a .bat-style pause in PowerShell Big Smile 
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit

If all goes well, when you run the script you should see something like this:

PowerShell script installing IIS and WebDAV

Here's the same thing in vbscript:

wscript.echo ""
wscript.echo "Creating IIS 7 answer file"
wscript.echo ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\answer.xml") 
    objFile.WriteLine "<ServerManagerConfiguration" 
    objFile.WriteLine "Action= " & chr(34) & "Install" & chr(34) & "" 
    objFile.WriteLine "xmlns= " & chr(34) & "http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1" & chr(34) & ">" 
    objFile.WriteLine "    <Role Id=" & chr(34) & "Web-Server" & chr(34) & "/>" 
    objFile.WriteLine "    <RoleService Id=" & chr(34) & "Web-Asp-Net" & chr(34) & "/>" 
    objFile.WriteLine "    <RoleService Id=" & chr(34) & "Web-ASP" & chr(34) & "/>" 
    objFile.WriteLine "    <RoleService Id=" & chr(34) & "Web-Windows-Auth" & chr(34) & "/>" 
    objFile.WriteLine "    <RoleService Id=" & chr(34) & "Web-Metabase" & chr(34) & "/>" 
    objFile.WriteLine "    <RoleService Id=" & chr(34) & "Web-WMI" & chr(34) & "/>" 
    objFile.WriteLine "    <Feature Id=" & chr(34) & "BITS" & chr(34) & "/>" 
    objFile.WriteLine "    <Feature Id=" & chr(34) & "RDC" & chr(34) & "/>" 
    objFile.WriteLine "</ServerManagerConfiguration>"
objFile.Close
Set wshShell = CreateObject("Wscript.Shell")
wscript.echo "Installing IIS 7"
wshShell.Run "ServerManagerCmd.exe -inputPath c:\answer.xml -logPath c:\IISInstall.log", 0, true
wscript.echo ""
wscript.echo "Installing WebDAV for IIS 7"
wshShell.Run "msiexec /i webdav_x86_rtw.msi /qn", 0, true
Set wshShell = CreateObject("Wscript.Shell")
wscript.echo ""
wscript.echo "Enabling WebDAV"
wshShell.Run "c:\windows\system32\inetsrv\AppCmd.exe set config " & chr(34) & "Default Web Site/" & chr(34) & " /section:system.webServer/webdav/authoring /enabled:true /commit:apphost", 0,
true
wscript.echo ""
wscript.echo "Creating and configuring a WebDAV authoring rule"
wshShell.Run "c:\windows\system32\inetsrv\AppCmd.exe set config " & chr(34) & "Default Web Site/" & chr(34) & " /section:system.webServer/webdav/authoringRules /+[users='*',path='*',access='Read'] /commit:apphost", 0, true
wscript.echo ""
wscript.echo "Configuring WebDAV"
wscript.echo ""
wscript.echo "    Allowing anonymous property queries"
wshShell.Run "c:\windows\system32\inetsrv\AppCmd set config " & chr(34) & "Default Web Site/" & chr(34) & " /section:system.webServer/webdav/authoring /properties.allowAnonymousPropfind:true /commit:apphost", 0, true
wscript.echo "    Not allowing Custom properties"
wshShell.Run "c:\windows\system32\inetsrv\AppCmd set config " & chr(34) & "Default Web Site/" & chr(34) & " /section:system.webServer/webdav/authoring /properties.allowCustomProperties:false /commit:apphost", 0, true
wscript.echo "    Allowing property queries with infinite depth"
wshShell.Run "c:\windows\system32\inetsrv\AppCmd set config " & chr(34) & "Default Web Site/" & chr(34) & " /section:system.webServer/webdav/authoring /properties.allowInfinitePropfindDepth:true /commit:apphost", 0, true
wscript.echo "    Allowing hidden files to be listed"
wshShell.Run "c:\windows\system32\inetsrv\AppCmd set cconfig " & chr(34) & "Default Web Site/" & chr(34) & " /section:system.webServer/webdav/authoring /fileSystem.allowHiddenFiles:true /commit:apphost", 0, true
wscript.echo "    Allowing access to hidden files"
wshShell.Run "c:\windows\system32\inetsrv\AppCmd set config " & chr(34) & "Default Web Site/" & chr(34) & " /section:system.webServer/webdav/authoring /fileSystem.allowHiddenFiles:true /commit:apphost", 0, true
wscript.echo ""
wscript.echo ""
Set wshShell = Nothing
wscript.quit

…and again as a .bat file (create the answer.xml file in the same directory before running)

@ECHO OFF
Echo Installing IIS 7
start /wait ServerManagerCmd.exe -inputPath c:\answer.xml -logPath c:\IISInstall.log
Echo Installing WebDAV for IIS 7
start /wait msiexec /i webdav_x86_rtw.msi /qb
cd %Windir%\system32\inetsrv
Echo Enabling WebDAV
AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /enabled:true /commit:apphost
Echo Configuring WebDAV
Echo Creating and configure a WebDAV authoring rule
AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoringRules /+[users='*',path='*',access='Read'] /commit:apphost
Echo Allowing anonymous property queries
AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowAnonymousPropfind:true /commit:apphost
Echo Allowing Custom Properties
AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowCustomProperties:false /commit:apphost
Echo Allowing property queries with infinite depth
AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowInfinitePropfindDepth:true /commit:apphost
Echo Allowing hidden files to be listed
AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /fileSystem.allowHiddenFiles:true /commit:apphost
Echo Allowing access to hidden files
AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /fileSystem.allowHiddenFiles:true /commit:apphost
pause
@ECHO ON
exit

 Hopefully this helps get you going with Configuration Manager installations on Windows Server 2008 computers a little faster!

 

~Jeff

 

 

 

Published Thursday, March 05, 2009 7:45 AM by jgilbert

Comments

No Comments