Create Many Site Collections via PowerShell

SharePoint

I had a problem this week where I needed to create many (like 30 or so) site collections in SharePoint 2010. These sites all have similar properties but different names and URLs of course. I also needed a way to remove all the sites I had just created easily.

New-SPSite and Remove-SPSite do the job, but when you have lots of site collections, you can’t be repetitive. Luckily for me, similar scripts have been written to handle my requirements so I just needed to hack them together. I used an excellent post by Gary Lapointe (@glapointe): Creating A SharePoint 2010 Site Structure Using PowerShell. I also needed to make some minor tweaks because results using PowerShell differs slightly from when you use Central Administration. Dan Holme (@danholme) provides those tweaks here: Create A SharePoint Site Collection With Windows PowerShell, UI Style.

Let’s get started!

First, we’ll create an XML file like the one Gary Lapointe shows. Since I only need to create Site Collections, I’ve removed everything else. Here’s how my XML file looks, named sites.xml:

                    
	
	
	
	
 

As you can see, we just copy all the lines between <SiteCollection> and </SiteCollection> for each new Site Collection we need. Next, specify the values you need for Name, Description, URL, etc.

Next, we need a script to create these sites. The script will loop through each <SiteCollection> block and create the site based on the values we’ve specified here. Nothing in the script needs to be changed because all our values are derived from the XML file above.

# Concept borrowed from Gary Lapointe: http://blog.falchionconsulting.com/index.php/2009/12/creating-a-sharepoint-2010-site-structure-using-powershell/
function Start-SiteCollectionCreate(
    [string]$settingsFile = "sites.xml") {
    [xml]$config = Get-Content $settingsFile
	
    $config.SiteCollections.SiteCollection | ForEach-Object {
        #Creating site collection
        Write-Host "Creating site collection $($_.Url)..."
        $gc = Start-SPAssignment
        $site = $gc | New-SPSite `
            -Url $_.Url `
            -Description $_.Description `
            -Language $_.LCID `
            -Name $_.Name `
            -Template $_.Template `
            -OwnerAlias $_.OwnerLogin `
            -OwnerEmail $_.OwnerEmail `
            -SecondaryOwnerAlias $_.SecondaryLogin `
            -SecondaryEmail $_.SecondaryEmail
            Stop-SPAssignment -SemiGlobal $gc
		# Associate Default Groups (Dan Holme: http://www.sharepointpromag.com/article/sharepoint/Create-a-SharePoint-Site-Collection-with-Windows-PowerShell-UI-Style)
		$MembersGroup = "$_.Name Members"
		$ViewersGroup = "Viewers"
		$web = Get-SPWeb $_.url
		$web.CreateDefaultAssociatedGroups($_.OwnerLogin,$_.SecondaryLogin,"")
		$PrimaryAdmin = Get-SPUser $_.OwnerLogin -Web $_.url
		$PrimaryAdmin.Name = $_.OwnerDisplay
		$PrimaryAdmin.Update()
		$SecondaryAdmin = Get-SPUser $_.SecondaryLogin -Web $_.url
		$SecondaryAdmin.Name = $_.SecondaryDisplay
		$SecondaryAdmin.Update()

		# Finish by disposing of the SPWeb object to be a good PowerShell citizen
		$web.Dispose()
        }
	}

# Execute the script			
Start-SiteCollectionCreate

Note near the top of the file we have $settingsFile set to “sites.xml.” Save this file as something like “CreateSitesXML.ps1” and then execute it in the SharePoint 2010 Management Shell:

.\CreateSitesXML.ps1

Finally, I wanted to remove all those sites that I just created. This is really cumbersome in Central Administration. We can use Remove-SPSite in PowerShell, but since I already have a list of sites in my XML file, lets use that instead. So here’s a script to remove those same sites:

function Start-SiteCollectionRemove(
    [string]$settingsFile = "sites.xml") {
    [xml]$config = Get-Content $settingsFile
	
    $config.SiteCollections.SiteCollection | ForEach-Object {
        #Removing site collection
        Write-Host "Removing site collection $($_.Url)..."
        $gc = Start-SPAssignment
        $site = $gc | Remove-SPSite `
            -Identity $_.Url `
            -Confirm:$false
            Stop-SPAssignment -SemiGlobal $gc
        }
	}

# Execute the script			
Start-SiteCollectionRemove

Name this script something like “RemoveSitesXML.ps1” and run it the same way you did to create sites.

Another note, if you look at the blog posts I referenced, you’ll see a value for “Content Database” in those versions. Add it back in if you need but for me, it was more of a bother because I didn’t have any requirements to use different databases.

0 comments

Free Business Productivity Training at Santa Monica College: Top 7 Reasons To Go

SharePoint

Do you use Microsoft Office at work or home and want to learn more? Do you want to know what the fuss is about social media in the enterprise? And how about those Microsoft “to the cloud” commercials, what does that mean?

Here’s your chance to find out. On April 2nd, 2011, Santa Monica College will host the SharePoint Saturday Los Angeles conference. It’s the only chance most people will have to talk directly to some of the brightest experts in the business productivity and collaboration space. And its only one day.

Here’s my top 7 reasons why you should attend:

1. Get expert training for free: Sure, you can find certified instructors just about anywhere, so what makes this event so special? First of all, it is absolutely free – no gimmicks. Second, where else could you possibly find a group of trainers which includes Microsoft employees, Microsoft partner employees, MVP’s, and trainers who are not only certified but are in the field actually doing this stuff? For a list of speakers, visit: http://sharepointsaturday.org/la/Pages/speakers.aspx

2. Get quality training: Training from experts is great, but what if you have questions? Smaller classrooms undoubtedly allow students to receive more attention and better quality training. On average, each session may have 10-20 people, a perfect environment to get your specific questions answered and interact with speakers one on one. For a list of sessions, visit: http://sharepointsaturday.org/la/Pages/meetings.aspx

3. Get connected: Many people certainly attend not only for the training but to network. With extended breaks, a long lunch, and post-conference events, its easy to meet like-minded individuals. Get business cards from speakers, sponsors and other attendees. Unwind after a full day of training at SharePint – an informal, relaxed, gathering at the local bar hosted by Rackspace. SharePint will be held at “The Daily Pint” at 2130 Pico Boulevard, Santa Monica.

4. Open your mind with partners: Partners are a huge part of the Microsoft eco-system. Before attending a SharePoint conference, I had no idea what was really out there to help me do my job or to make things easier for users. Several software companies, consulting companies and service providers will be on-hand to answer questions. For a partial list, see: http://sharepointsaturday.org/la/Pages/sponsors.aspx

5. Have a lunch on us: The event will certainly satisfy your hunger for knowledge as you soak up expert advice, tips, and best practices. Take a break to soak up the Santa Monica sun and have a lunch on us. Free lunch, beverages, and snacks will be provided to everyone attending.

6. Win great prizes: Throughout the day, you’ll have chances to win some excellent prizes. Many speakers will have free giveaways at their sessions. We’ll also have things like books, posters, and computer peripherals (like the new Microsoft Arc mouse or a Kodak scanner) that you could win. Fill out evaluation forms to win even cooler prizes like a Toshiba Netbook.

7. Get involved: We all win when we support each other. Find out how to participate in other local events and user groups in the area. Southern California has an active community of user groups like the SFVSPUG, LASPUG, LADOTNET and many many more.

So take the first step and register: http://spsla.eventbrite.com

Finally, get more information and stay up to date by visiting http://sharepointsaturday.org/la or follow along on twitter using hash tag #SPSLA.

0 comments

San Fernando Valley SPUG Meeting #2

SharePoint

Come out and get some free training and insights from some SharePoint experts. If you live in the San Fernando Valley (California) area (or Ventura County, LA County) you’re invited to the SFV SPUG being help February 15th from 6:30 PM to 9:00 PM. Its free, just register.

We’re planning two sessions, which I think are going to deliver a lot of value. We have Axceler presenting their award winning product ControlPoint which is used by Administrators and business users to simplify SharePoint management.

We also have Nedra Allmond presenting some lessons learned from a quickie migration. Nedra is on the front-lines facing real-world business challenges so this is not a theoretical talk but an actual discussion around what problems you may face during a migration.

As always, we will have refreshments, kindly provided by K2. If you’re not familiar with them, read about their SharePoint products at http://www.k2.com/

The user group meeting is taking place at Oxford Institute of Technology, who have graciously provided the space so big thanks to them.

Check out the meetup details here: http://www.meetup.com/San-Fernando-Vally-SharePoint-Professionals/events/16410398/

0 comments

Why so much twitter?

SharePoint

In previous posts on this blog, particularly a recent one called “Automating your SharePoint Install,” I mentioned several people and included links to their twitter timeline. Here they are again:

If you’re involved in SharePoint, you need to be on twitter. This is really my primary method of gaining knowledge and reading news regarding SharePoint. I tried hard for many months to keep up with the latest news, trends, and updates through blogs (RSS reader) and that was really not enough. It was too hard to distinguish what’s pertinent and what was just opinion articles or specific problem resolutions on blogs. I admit, it took me a while to figure out how to use this twitter thing that was creating so much buzz. Twitter has many uses but I’m going to focus in on two things: community involvement and knowledge sharing.

The experts I’ve listed above regularly tweet (twitter term for post or a posting), usually sharing blog posts or other links to resource that they’ve found useful. In fact, the “re-tweet” helps to ensure the most important or pertinent information gets seen by everyone and bubbles up to the top on trending charts. So how do you get started?

1. First, chose a good client. I’ve tried a few but keep coming back to TweetDeck. It’s one of the most used, has a clean interface with just enough information and is easily customizable. For my Android-based phone, I prefer twidroyd for the same reasons plus its ease of use. And finally, if your desktop or phone aren’t available, I recommend using Hootsuite which is a web-based twitter client. I like it much better than the office twitter.com web site.

Choosing a good client will really make it easier to start using twitter. In fact, it wasn’t until I started using TweetDeck that it all made sense to me. Be sure to display columns for Mentions, Direct Messages, and Favorites. I use Favorites as a bookmark to look at things later when I have more time.

2. Find “people” to follow who will provide the information you need without flooding you with personal information. I put “people” in quotes because some of the best twitter accounts are not actual people; they may be programs, or a team account, or a company account. So here’s my recommendations to get you started:

  • @SharePoint : The SharePoint Product Group. Besides their own information, they do retweet useful information from the community.
  • @SharePointRiver : A river of information on SharePoint
  • @Erik_Berlin : Erik retweets a lot of popular posts, so let him do the sifting for you.
  • @TeamEUSP and @EUSP : Team account for one of the most popular SharePoint sites, EndUserSharePoint.com
  • @SharePointBuzz : Similar (maybe better) to SharePointRiver, will re-tweet the most useful links, resources and tweets about SharePoint.

Once you get used to that, you’ll be able to see where these accounts are sourcing their information. Much of it will come from MVP’s and experts like the those listed at the beginning of this article. You can visit their timelines and follow them if you decide to. New features in twitter now recommend people you should follow and show you who is similar to you.

3. Interact. Find something useful on the internet? Have your own blog or link? Figure something out that you want to share? Have a question for the pros? Write a tweet, if it’s about SharePoint, you can append the #SharePoint hashtag.

But what use is this if no one is following you, no one will see it right? Wrong. Many people (like me) also search for tweets using hashtags, in my case the #SharePoint hashtag. Also, popular internet engines like Bing and Google now do “real-time search” and will pick up your tweets. Finally, someone may come along and click on your timeline. If they find it interesting, you’ll gain followers.

If you’re a SharePoint IT Pro, Developer or business user, twitter can be a useful tool in your arsenal. Now that I’m comfortable with it, I can skim through 100 tweets in under a minute, tag the ones useful to me and read them later. This actually saves me a lot of time over the old blog RSS reader method. Plus, because its real-time, I know what’s going on right away and that can be very useful. Case in point, the October Cumulative Update was released and almost immediately retracted because it could break your SharePoint farm. Because of the nature of twitter’s real-time capability, the awesome SharePoint community and reinforcing tools like “re-tweets,” I was able to know, right away, NOT to install the update. This probably saved me a few days worth of work.

There are many others I wish I could list, maybe hundreds, who contribute via twitter. I’m grateful for the involvement in the community, the knowledge they’ve imparted on me and I’m always in awe of all the new things they discover and share. You could click on my twitter profile (@wahidsaleemi) and take a look at the people who I’m following. Most of these are SharePoint professionals, though there are a few friends and non-SharePoint folks. Another way to find more people, besides using the hashtag search, is to search for SharePoint lists in user’s profiles.

Want some quick follow up reading? Christian Buckley (@buckleyplanet) published a short ebook on the topic: http://bit.ly/aiYKWR

1 comment

Working with SQL Aliases

SharePoint

By now, many SharePoint Administrators have heard this “best practice:” Use SQL Aliases. Recently, I was surprised to hear that this may not be unanimous – Todd Klindt (@toddklindt) in his weekly netcast argues against it. Todd also pointed out Todd Carter’s (@toddca) blog post where he suggests always using SQL Aliases.

In my work, I always employ SQL Aliases, even on single server farms where SQL and SharePoint are on the same server. Seems like a waste of time, doesn’t it? Well, it takes about half a minute to setup but can save hours if you get into trouble.

Let’s look at a common scenario. Your developers need SharePoint setup quickly so they can create some gee-whiz solutions. So, you quickly create a SharePoint farm accepting all defaults (or use a script mentioned in a previous post) and deliver it to your developer buddies.

Little did you know, only 3 months later, you’re running out of disk space or SQL gets corrupted or you finally get your shiny new blade servers and want to build out a new SQL cluster for your development environment. Anything could happen…

Enter: SQL Aliases. Without an alias, you’d be setting up a brand new SQL server and SharePoint from scratch. You’d have to migrate all the developer work, their solutions, their settings and have to deal with whining because someone is “down” until you’re done building the new system.

SQL Aliases are like host names, somewhat. It’s the name everyone knows and remembers (including SharePoint). In DNS (or host files), the name stays the same, though the IP could change. Aliases are similar, you can change your SQL Servers name, but it’s alias will remain. All you’d have to do is update a “pointer.” One BIG difference worth mentioning though: DNS is server-side, meaning you go to your DNS server and update a record; SQL Aliases are client-side, like hosts files. Only the computer on which you created it knows about it and will use it. So yes, you have to create this on any client/computer that you want accessed this way. This usually just means, all your SharePoint servers in the farm.

So now, hopefully, you see the benefits of using SQL Aliases. I’ll show you how to set one up in less than 30 seconds.

These steps are taken from my Wiki http://wiki.wahidsaleemi.com/Pages/SQL_Server_Setting_Alias

  1. Click Start –> Run –> cliconfg.exe (notice there is no i in confg)
  2. Select the Alias tab and click Add…
  3. Specify the Server alias (for example: SharePoint_DB or SQLPoint1 or whatever)
  4. Select the TCP/IP Network library.
  5. For Server name, enter the SQL Server Name (if using default instance) or use UNC notation if using non-default instance (e.g., \\servername\instance)
  6. Uncheck Dynamically determine port and use the default port of 1433.
  7. Press OK. Repeat this on any client that is part of the SharePoint farm.
image

If you want to use Aliases on your SQL Server, or if you have an all-in-one box (SQL + SharePoint), follow this procedure instead:

1. By default, Windows comes with a SQL client called “cliconfig.exe” but as I’ll show you later, this doesn’t always work.

2. Next, run SQL Server Configuration Manager and expand the “SQL Native Client 10.0 Configuration” nodes (both of them).

 image

Take note that one has (32bit) and the other doesn’t. Depending on the client, one will be used over the other so it’s best to configure both nodes identically.

3. Right-click on “Aliases” and select “New Alias…” A dialog box will open.

a. Use any name for your Alias, for example “SharePoint_DB”
b. You should specify the port number, SQL’s default is 1433. Leave the protocol at TCP/IP.
c. For Server, enter just the server name if you’re using the default SQL instance (e.g., Server01_Web). If you’re using a named instance, you need to enter the server name and instance using UNC notation (e.g., \\Server01_Web\NewInstance).

d. Click OK and repeat the steps for the other “Aliases” node.

Now that your Alias is created, you can try to connect to it using SQL Server Mangaement Studio or another method. So, instead of using the “Server Name” to connect to SQL, use your new Alias, it should work just fine.

When installing SharePoint, and it asks for your SQL Server name, just specify the SQL Alias. This way, if anything ever goes wrong with SQL, you can just change the Alias to a new server and not have to re-configure SharePoint.

22 comments