Select Page

Recently (at the European SharePoint Conference 2013 and at several user group meetings) I have been demo’ing a script I had knocked up to create SharePoint content databases “DBA style”; i.e. by pre-creating and configuring the databases SQL Server side, and then adding them as content databases SharePoint side.

In order to be of use, I wanted the script to be runnable (is that a real word?) from the SharePoint farm so it represented a (kind of) “DBA-less” way to create content databases that are correctly formed and well configured for some basic best practice such as auto-growth.

Provided is a modular script that defines a bunch of functions then executes them according to needs. The needs are defined within an associated XML configuration file (sample is also in the zip file) that the script parses to build out the databases.

There are some caveats:

  1. The script is, of course, provided “as is” with no warranty of any kind expressed or implied. Use at your peril and remember, test!
  2. Take the time to walk through the script and XML config file so you can change the relevant bits for your environment
  3. This script is really an example of how to do something neat and is not necessarily the correct way to create a content database as this will vary from farm to farm
  4. The script has been created as an educational aid and so is a little verbose in places (look how we delete the databases) but will hopefully help you by being like this
  5. This script will DELETE databases without requesting a confirmation so exercise caution!

I’ll gladly answer questions if you have any – please do so via the comments, I do monitor them.

How does the script work?

Simple really:

  1. Loads up the config file
  2. Loads up the SQL SMO assemblies
  3. Removes the databases if they already exist (it is for demo purposes after all)
  4. Adds the databases to SQL and configures them
  5. Adds the databases to SharePoint
  6. Job done!

Within the SQL piece, dbaccess logins will also be added to the database (and if needed to the instance) to allow SharePoint to access the databases.

The script and config file zip can be found here.

Please; test, test, test!

more to follow…