How to rename SharePoint 2010 … Everything!

This is the first in a series of articles to pull together all the various guides around the web to rename SharePoint 2010 databases, servers, services, and other objects. Over the coming weeks I’ll publish these articles:

  • Introduction & Windows PowerShell (this article)
  • Rename the Configuration and Content Databases
  • Rename the State Service Database
  • Rename Alternate Access Mappings
  • Rename Servers
  • Rename SharePoint Site Groups and Sites and IIS Sites
  • Rename IIS Application Pools

Why Rename SharePoint 2010 Objects?

As SharePoint 2010 installations grow in size, admins and DBAs are facing increasing frustration in dealing with Microsoft’s propensity to guarantee unique names by gluing GUIDs on the back of every name. This has gotten to be such an issue that half the reason the AutoSPInstaller script was created was to eliminate the GUIDs where possible. (Note that aside from simply being unattractive, names with GUIDs are a royal pain when you have to write scripts)

A standard SharePoint 2010 installation leaves nasty database names.

However, you may still end up with awkward names for various reasons. There are instructions on how to rename these artifacts scattered around the web; this is my attempt to gather everything into one place.

Windows PowerShell to Rename Content Databases and other SharePoint Objects

If you’re working with SharePoint 2010 and you’re not working with Windows PowerShell, it’s time to start. Virtually all the guidance here is PowerShell-based. I’ll be working with the SharePoint PowerShell provider, which has the SharePoint extensions enabled as well as the path to the 14 hive defined – it makes a great command prompt for SharePoint as well.

Some Windows PowerShell tips before we proceed. You will definitely want to understand piping. The short, simple explanation is that when you use the pipe character ( | ) between commands, it redirects the output of the first command into the second command.

So this script:

Get-SPDatabase | SELECT Name, ID

Returns all the SharePoint databases (Services Databases, Configuration Databases, Content Databases) from the current farm. Think of this as a collection of objects. This collection is then sent to the SELECT command, which will select out the Name and ID properties and list those for all the objects piped to it. Understanding the “way of pipes” will make a huge difference in your productivity with Windows PowerShell.

The other little tidbit about PowerShell and SharePoint objects are how to get the one you want. When you type Get-SPDatabase in the SharePoint Management Shell, you’ll get something looking like this:

image

Using the SharePoint 2010 Management shell.

So how do you get the one you want? The most popular way to pick out a specific object is to use the SELECT-OBJECT cmdlet, like this:

Get-SPDatabase | WHERE-OBJECT { $_.Name -eq "SomeDatabase" }

This line takes that collection of SPDatabase objects output by the Get-SPDatabase cmdlet, and pipes it to the WHERE-OBJECT cmdlet. That takes the collection of objects and uses the statement in curly braces to filter out the database we’re looking for. (“$_” is shorthand for “the current object”)

[amazon_enhanced asin=”1118021983″ container=”AmazonTable” container_class=”alignleft” price=”New” background_color=”FFFFFF” link_color=”000000″ text_color=”0000FF” /]

The problem, of course, is that we have these nasty GUID names to deal with, so we’re going to be copying and pasting from the list of databases. If we have to copy and paste anyway, then we can cut to the chase with this command:

Get-SPDatabase -ID c3c72c94-513b-4ff1-9346-3646f1bdc7ff

This gets us one of the Content Databases – in this case the one for the Central Admin site. The ID is a GUID, and easily selectable to copy and paste from the list. This is the second way to return a specific database, and until we get the names trimmed down, it’s the most straightforward. In addition, the –ID parameter is available for virtually every SharePoint object type, and will obviously always be unique.

With that under your belt, next time we’ll tackle renaming the SharePoint Content Databases, and I’ll address why you should never rename a SharePoint Farm Configuration Database.

SharePoint 2010: Create a Pretty Table of Farm Services

Once you’ve built a SharePoint 2010 Farm, you usually need to document it. Part of the documentation should be a list of what services are running on which server. Most folks will probably either screen shot the Central Admin page showing the services running on a server, but that only shows one server at a time, so you need a screen shot for each server, and these can be tough to read.

Or you might use a PowerShell script to list the services running on each server, which is somewhat better, but still tricky to read critically.

Wouldn’t you rather have a chart like this in your documentation?

SharePoint Services Chart in Excel

 

Well follow along and find out how!

Listing the Services

First we’ll get the list of services by server. Start the SharePoint 2010 Management Shell (Start –> All Programs –> Microsoft SharePoint 2010 Products ). The PowerShell command to list running services by server is as follows:

Get-SPServer |
Foreach-Object {
    $_.ServicesInstances |
    Where-Object{
        $_.Status -eq "Online"
    }
} |
Select TypeName, Parent |
Export-csv c:\path\Services_List_$env:computername.csv

This will produce a list like this:

#TYPE Selected.Microsoft.SharePoint.Administration.SPDatabaseServiceInstance
"TypeName","Parent"
"SharePoint Foundation Search","SPServer Name=MyFarmServer01"
"Information Management Policy Configuration Service","SPServer Name=MyFarmServer01"
"SharePoint Server Search","SPServer Name=MyFarmServer01"
"Managed Metadata Web Service","SPServer Name=MyFarmServer01"
"Microsoft SharePoint Foundation Usage","SPServer Name=MyFarmServer01"
"Business Data Connectivity Service","SPServer Name=MyFarmServer01"
"Secure Store Service","SPServer Name=MyFarmServer01"

…as a csv file. If you open it in Excel, you’ll have a sheet which looks like this:

Services In Excel

 

Uh, okay – now what? Now it’s Excel magic time!

First we can open out the columns to see all our info:

Columns Opened

 

Of course the server names look icky (technical term), so we run a quick find/replace – select the column, then click the “Find & Select” button in the ribbon. Search for “SPServer Name=” and replace it with nothing, then do a Replace All:

Find and Replace

 

This should give you something that looks like this:

Fixed Server Names

(Note: You may also have the mail server and database servers listed. I had already deleted them from this list, since they don’t add much. It’s up to you whether to leave them or not)

You will need to delete the first line (#TYPE Selected.Microsoft.SharePoint.Administration…)

Now you can either click & drag to select all the rows, or just click any cell in your list. Then click “Format as Table” and select a table format (I’m partial to blue with alternating rows). You’ll get a little dialog with the range selected (it will have automatically selected the full range). Check “My table has headers” then click “OK” You should get a formatted table as shown:

Formatted Table

 

Click on “TypeName” and type “Services,” then replace “Parent” with “Servers.” Now click in C1, the column next to Servers, and type “Count” – once you leave the cell, Excel should expand the table to include the new column:

Added Count

Click in C2 and type a “1” then the enter key. Then click back in the C2 cell, then click the little “handle” in the lower right of the cell highlight and drag it down the length of the table:

Click Handle

 

This should fill the column with number 1’s – you’ll see why in a moment.

Now click the Table Tools / Design tab on the ribbon, and click the “Summarize with PivotTable” button. Keep the defaults – the selected table and to insert the table in a new spreadsheet, then click OK. This will open the PivotTable editor in a new sheet:

PivotTable Editor

In the field list on the right you should see “Services,” “Servers,” and “Count.” Drag “Services” down to where it says “Row Labels.” Then drag “Servers” to “Column Labels” and “Count” to “Values”:

Pivot Table Fields

 

Your pivot table should now look like this:

Pivot Table

 

You can type over “Row Labels,” “Column Labels” and “Sum of Count” to more intelligent names like “Services,” “Servers,” and the Farm Name. Let’s also get rid of those Totals – right-click anywhere in the Pivot Table and select “PivotTable Options” to open the options dialog. Select the “Totals & Filters” tab, then uncheck “Show grand totals for rows” and “Show grand totals for columns”:

Removing Totals

Click “OK”.

Finally, click on any of the “1” values, then on the Home tab in the Ribbon click “Conditional Formatting” then “Icon Sets” and the icon set with the check, exclamation, and red “X.” This will format the single cell, but you’ll see a small icon next to it – click on it:

Selecting Pivot Table values

From the menu, select “All cells showing ‘MyFarm’ values” – this should cover the whole range with the symbols you selected:

All Selected Symbols

One step left – let’s get rid of those ones digits! Click on the “Conditional Formatting” button and select “Manage Rules.” In the Conditional Formatting Rules Manager, select your rule, then click the “Edit Rule” button. In the “Edit Formatting Rule” dialog, check “Show Icon Only.” Then click “OK” and “OK” again. Select all the check marks, click the formatting button to center them, and voila!

Final Table

I’m working on macros to make this easier, and after that comes an Add-In to copy the table to an editable range and export it to XML, and finally a PowerShell script to take that XML script and use it to flip services on and off… Hopefully…