Setting SharePoint content databases offline via Script


Body:

If you followed the TechNet documentation for Set-SPContentDatabase and try to take SharePoint content databases offline by running Set-SPContentDatabase –Status Offline you will be really disappointed to know that it just does not work. If you look at the TechNet documentation, the type associated with Status is Microsoft.SharePoint.Administration.SPObjectStatus, valid values are “Online”, “Disabled”, “Offline”, “Unprovisioning”, “Provisioning”, “Upgrading” See this link for more information

Unfortunately passing none of the above values work. So I decided to look into the source of manage content database settings page by doing a view source in browser

cdbsettings

What I found in view source is valid values for Database Status is 0 and 1 as shown in screenshot below.

cdbsettings1

So to Take Content Database Offline you have to run the following script

Get-SPContentDatabase “{replace with name of content database}” | Set-SPContentDatabase –Status 1

Bring Content Database Back Online

Get-SPContentDatabase “{replace with name of content database}” | Set-SPContentDatabase –Status 0

Cheers,

</Ram>

Published: 5/9/2012 12:03 PM

Comments (0)