Update: Post now resides at new blog site! http://www.tcscblog.com/2010/12/28/create-site-collection-in-new-content-database-script/
In 2007 you had the stsadm command createsiteinnewdb. However, there is no PowerShell equivalent command in 2010. So, I created a script that performs the same action. It takes in input, creates a new site collection in a new content database, then sets the max site count to 1 and warning site count to 0 to lock it down from any other site collection being added to the database. This works great for scenarios where we build one site collection per department, division, etc.
Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
$server = Read-Host “Enter SQL Server”
$dbname = Read-Host “Enter Database Name”
$webapp = Read-Host “Enter Web Application URL”
$site = Read-Host “Enter New Site Collection URL”
$owner1 = Read-Host “Enter Primary Site Collection Admin”
$owner2 = Read-Host “Enter Secondary Site Collection Admin”
New-SPContentDatabase -Name $dbname -DatabaseServer $server -WebApplication $webapp | out-null
New-SPSite -URL $site -OwnerAlias $owner1 -SecondaryOwnerAlias $owner2 -ContentDatabase $dbname | out-null
Get-SPContentDatabase -Site $site | Set-SPContentDatabase -MaxSiteCount 1 -WarningSiteCount 0
Write-Host ” ”
Write-Host “Site Collection at” $site “has been created in the” $dbname “content database” -ForegroundColor Yellow
When you access the site you are then prompted to select the appropriate template.
_____________________
Sponsors *Trusted SharePoint Ads Only!*
Packaged Enterprise Search
for SharePoint.View a quick online demo here! Surfray.com/Ontolica
Free Outlook Sidebar!
Access SharePoint from Outlook w/ harmon.ie Sidebar. Download Now!
SharePoint Admin Toolkit – Download now!
FREE Tools to Simplify SharePoint Management
SharePoint Migration Tools
Sharegate: No-Brainer Migration Tools for SharePoint. $375.
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
8 Tips to Increase SharePoint Adoption
Download Free Whitepaper
11/22/2010 at 7:00 am
Hi, will this script also work if i want to create host named site collections?
11/22/2010 at 7:14 am
It should, but you need to make sure you add the host header URL and HostHeaderWebApplication switch to the New-SPSite command. Check the TechNet article on New-SPSite for details: http://technet.microsoft.com/en-us/library/cc424952.aspx
12/07/2010 at 7:49 am
Thanks for the great example, it’s helped allot… though I’m stuck with a migration issue… I have a 2007 web application with multiple SC’s in thier own DB’s … how can these multiple content DB’s be migrated to 2010 using the attach/detach approach ?
Here’s the basic structure
http://intranet – intranet_content
http://intranet/departments/legal – intranet_legal_content
http://intranet/departments/sales – intranet_sales_content
http://intranet/departments/security – intranet_security_content
tia
Gerald
12/07/2010 at 8:21 am
Glad to hear that the script helped!
You backup each DB and move it/restore it to the SQL Server that is allocated for SharePoint 2010. Once there, you can perform Test-SPContentDatabase against the restored DBs to determine their readiness for migration. Once all issues/missing features etc have been resolved, you can run Mount-SPContentDatabase to attach the database to SharePoint 2010 which kicks off the upgrade. You would need to do your Intranet_Content DB first since I’m assuming that is where the Root Site Collection is stored. Do a search for these two PowerShell commands as well as SharePoint 2010 upgrade and you will find tons of info! Hope that helps and check out http://www.tcsc.com, my employer, should you need any assistance with this. I handle most of the SharePoint migations and upgrades here.
12/07/2010 at 8:28 am
Thanks for the quick reply, I am already using powershell to migrate several of my web applications using the commands you’ve suggested… I can migrate the primary site no isssue.. but where it gets confusing, I re-created all of the managed paths within the primary web application, then when re-creating the SC’s how can I specify the 2007 content database ? or is there another apporach I’m missing ?
tia
Gerald
12/07/2010 at 12:55 pm
You do not need to “re-create” a SC and point it to the 2007 content database. You use mount-spcontentdatabase and point it to the primary web app. If your managed paths are already setup, then once the upgrade has completed then your SC will just be there…no need to create anything. Perhaps I’m misunderstanding you though…
12/07/2010 at 1:33 pm
That’s what I was hoping, but no such luck… unless I’m doing something incorrect when I build the web application, if I don’t re-create the managed paths and SC’s nothing appears in the migrated web application… here’s the steps I’m taking…
back up and restore all my 2007 content db’s to the new SQL server…
#build web app
new-spwebapplication -name $webapp_name -Port $webapp_port -HostHeader $webapp_hostheader -URL $webapp_url -ApplicationPool $WebAppPoolName -ApplicationPoolAccount $appPoolAccount -DatabaseName $WebAppDB -DatabaseServer $databaseServerName
#build SC
new-SPSite -url $webapp_url -OwnerAlias $sc_owner -Language $sc_language -Template $sc_template -Name $webapp_name
#remove the temporary content DB
Get-SPContentDatabase -WebApplication $webapp_url | Remove-SPContentDatabase -confirm:$false
#mount the primary 2007 content DB
Mount-SPContentDatabase $WebAppConvertDB -webapplication $webapp_url
after this step there are no SC’s or managed paths listed in CA, if I mount the additional content databases with out any managed paths or SC’s they are just there… un-usable…
Thanks
Gerald
12/07/2010 at 3:11 pm
After Build Web App, do you go in through the UI on CA and create the appropriate managed paths? I’ve heard issues where you need to create the managed paths yourself first before doing Mount-SPContentDatabase.
If you go to CA and under Upgrade and Migration > Upgrade Status does it say successful or failed? What do the logs say? The log location can be found at the same Upgrade Status page.
If that doesn’t work, build the web app, SC, remove temp DB all through the UI…only do Mount-SPContentDatabase through PowerShell and see what that gets you.
04/12/2011 at 10:20 am
Pretty good script mate… Im using it!
01/31/2012 at 10:18 am
Awesome script! Thanks!!
09/07/2012 at 11:46 pm
Nice site
12/27/2012 at 2:40 pm
Thank you for the script.. It worked for me as well…