Use PowerShell to create a whole bunch of SharePoint content


This post is one that came out of a conversation with another SharePoint buddy of mine. We were discussing how to evenly place SharePoint Site Collections into multiple content databases, and how it’s sort of a nice, relatively unknown ‘feature’ of SharePoint that it will use a round-robin approach of placing them into all available content databases for a web application. While it’s very common to place individual SharePoint Site Collections into their own content database, and that’s certainly a good approach – it is certainly a good option to pre-create several content databases and allow SharePoint to handle the balancing act, as it were…

Having said that, here is what I did to prove it out for the purposes of this blog post. I already had an empty web application at http://testtest.adventureworks.com with no content databases from some other testing I’ve done recently:

1. Store the Web Application in a variable

$wa = Get-SPWebApplication http://testtest.adventureworks.com

2. Create 10 Content Databases – note the 1..10 that I’m piping to the ForEach-Object cmdlet. This is a great shorthand way to quickly create a number of ‘things’ in PowerShell.

1..10 | ForEach-Object {
$name = “SPContent_”+$_
New-SPContentDatabase –Name $name –WebApplication $wa
}

3. Create 100 Site Collections – note again the use of 1..100. Also, these will all be team sites under the /sites managed path.

1..100 | ForEach-Object {
$url = “http://testtest.adventureworks.com/sites/”+$_
New-SPSite –Url $url –Template "STS#0" –Name $_ -OwnerAlias domain\user
}

And once all of that is done, you should be able to see a nicely balanced web application with 100 site collections evenly distributed across 10 content databases:
ContentDBs

Happy SharePointing (and PowerShelling)!

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s