Tuesday, April 10, 2007
Update: This post describes the use of Sysprep with SharePoint in Standalone mode. I've since posted a follow-up that updates this to work with a Complete install and SQL Server.
If you're doing SharePoint development you're probably doing it on a virtual machine, and if you're not you probably should be. Often it's useful to have more than one machine available whether that's for multiple clients, projects or developers. If you're working in a standalone or workgroup environment you can probably get away with creating one virtual machine and copying it as many times as you need additional machines. In a domain environment however, this isn't really going to work for you. You need to change the SID of the machine, give it unique name on the network, join the domain and ensure that SharePoint is configured ready for you to start developing on. One way to tackle this would be to use NewSID, rename, join the domain manually and then fix SharePoint. A better solution would be to use Sysprep and automate the whole process.
First, create a new virtual machine, install Windows Server 2003 and run Windows Update making sure you install the .NET Framework 2.0 and 3.0. Once those are installed add the Application Server Role from the Manage Your Server utility. Next, install WSS or MOSS, selecting Typical from the install options to perform a standalone installation. Once this has finished the SharePoint Products and Technologies Configuration Wizard will run. It's important that you don't run the wizard at this time, you'll see why later on. Finally, finish off the installs with Visual Studio 2005 and any of your other favorite tools. Others have written about how to install a standalone SharePoint environment in more detail and there are also instructions available on TechNet for both WSS and MOSS.
Next, you need to grab the correct version of Sysprep, there's one for each Windows Server 2003 Service Pack. I originally put this together using Sysprep for SP1, before Windows Server 2003 Service Pack 2 was released, but I don't know of any reason why you shouldn't use Sysprep for SP2. While you're at it, download WssSysprep.zip which contains the scripts and settings we'll use with Sysprep.
If you're using SP1, Sysprep is distributed as a CAB file which you should extract to c:\Sysprep. The SP2 version looks like it's distributed as a hotfix so this will need installing, but the net result should be the same. Once you've done that, extract the contents of WssSysprep.zip (which you've already downloaded if you're paying attention) to c:\ which will add a couple of files to c:\Sysprep and create c:\Scripts.
Sysprep is configured using sysprep.inf which you need to create in c:\Sysprep with settings specific to your environment. You can either create this file by hand using ref.chm as a guide, or if you prefer you can use Setup Manager (setupmgr.exe) to help you. To ensure that this is a completely automated process, you need to include enough information in the configuration file to prevent you from being prompted for more during setup. I have included my sysprep.inf file renamed as sample.inf as a reference. In addition to your own preferences, you need to include the [GuiRunOnce] section from sample.inf. Any commands entered here are executed after the first user logon following setup. In this case, we call wssconfig.bat which will provision a SharePoint site and configure it ready for use.
Since it's where most of the magic happens, let's take a look at the important bits of c:\Scripts\wssconfig.bat.
1: "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\PSCONFIG.EXE" -cmd configdb create
2: "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\PSCONFIG.EXE" -cmd setup
3: "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE" -o siteowner -url http://localhost -ownerlogin %userdomain%\%username%
4: "C:\Scripts\wssdebug.exe" http://localhost /enable
Earlier, when you installed SharePoint you didn't run the Configuration Wizard. If you had, a site would have been provisioned but it wouldn't have survived the Sysprep process. Instead, we have Sysprep call this batch file which uses psconfig.exe to provision a site for us after setup has run. (The use of psconfig.exe in this way came from this post.) Sysprep calls this file with the "/sysprep" switch to indicate that there are no existing sites to be removed. Once psconfig.exe has created the site collection we use stsadm.exe to set the current user as the site collection owner. This will require administrative privileges to run, so in an environment where you're potentially distributing this to several developers I would add the built-in NT AUTHORITY\INTERACTIVE group to the local Administrators group. I'm happy to do this in a development environment but you may prefer to add specific domain accounts which will also be fine. Last of all, we run wssdebug.exe to make a few tweaks to make SharePoint a little more developer friendly.
That's pretty much all we need to make this work. However, I would recommend you make a couple of other changes now to save you making them each time you create a new machine. I like to have the SharePoint "bin" directory included in my path to make it easier to run stsadm.exe, and a shortcut to the 12 hive on the Desktop is always useful. Andrew Connell has a number of other good suggestions. I'd also set the IE and Firefox home pages to localhost now as well. Bear in mind that you're likely to want these tweaks available to all users of the machine so create desktop shortcuts in the All Users profile and consider updating the Default Profile with user specific settings. The Sysprep documentation suggests that any settings made to the Administrator profile will be copied to the Default Profile when Sysprep runs. This never seems to work for me (maybe it's an XP only thing?) so instead I follow this Knowledge Base article. Finally, you might want to compact your virtual hard disk since it may have become fairly sizeable by now.
At this point I'd take a copy of the virtual hard disk to make it easy to come back and make changes in the future. Once that's done you can go ahead and run Sysprep to reseal the machine. (You can use the included sysprep.bat which simply calls Sysprep.exe with the /reseal, /mini and /shutdown switches.) Once the machine has shutdown I like to mark the virtual hard disk file as read-only and remove the associated virtual machine to prevent me starting it up accidentally.
You now have a virtual hard disk which you can copy as many times as you like, for as many developers as you need. (And if you zip it up it should hopefully still fit on a single DVD.) The first time it starts up it will give itself a unique name and join your domain. When the first user logs on a new site will be provisioned, the user will be made site collection owner and SharePoint will be configure for debugging.