We’ve recently started making some decisions as to the layout of our primary intranet site (the information architecture of the site that is). One of the things we decided was that we wanted all divisions to be in separate site collections but for each of them to share a single database. We also wanted to create a central document center site and knowledge base site which would, along with all remaining root content, be in it’s own database. Our current structure just has everything in one large site collection. In order to accomplish this I needed to take the primary content database offline while I moved/converted divisional web sites into site collections.
I was able to use the existing addcontentdb command to create the new content database but I needed to create a new command, called gl-managecontentdbsettings, to take the existing one offline (I already have a command to convert a sub-web to a site collection). I decided that rather than just limit the command to changing the status I’d go ahead and make it so that it could adjust any of the properties that you could otherwise adjust via the browser by going to the Manage Content Database Settings page (Central Administration > Application Management > Content Databases > Manage Content Database Settings). This included the status, the maximum number of allowed sites, the number of sites allowed before a warning is sent, and the search server (there’s already a built in command to remove a content database so I didn’t worry about that).
The code to do all of this was extremely simple – the only thing that made me pause for a bit was the setting of the search server (I had to dig into Microsoft’s code to see how that was accomplished but in the end it turned out to be pretty simple):
The command I created is detailed below.
Using this command is straightforward. The only odd part is the setting of the search server. If you want to set the value simply provide the server name along with the "-searchserver" switch. But if you want to clear the value just provide the "-searchserver" switch alone with no value (not "" but literally no value). I probably should have done this differently but it works. The other thing that’s odd is that if you look in the browser you’ll see that the drop down for status contains "Ready" and "Offline" – this actually corresponds to "Online" and "Disabled" (which is strange because the SPObjectStatus enum contains an "Offline" value but if you tried to use that to set it offline it doesn’t appear to have an affect (at least it doesn’t change the value in the browser – I didn’t actually test if it prevents new sites from being created). The syntax of the command can be seen below:
C:\>stsadm -help gl-managecontentdbsettings stsadm -o gl-managecontentdbsettings Sets the status and site limits for a content database. Parameters: -dbname <content database name> -webapp <web application url> [-status <online | disabled>] [-maxsites <maximum number of sites allowed in the db / -setmaxsitestocurrent (sets the max value to the current value to keep the database online but prevent new sites from beeing added)>] [-warningsitecount <number of sites before a warning event is generated>] [-searchserver <search server (leave empty to clear the search server)>]
Here’s an example of how to set all the properties of a content database:
stsadm –o gl-managecontentdbsettings -webapp "http://intranet/" -dbname intranet1_site_pair -status disabled -maxsites 15000 -warningsitecount 9000 -searchserver spsearchsvr