SharePoint 2010 – List all Sites where a feature is activated with PowerShell

Quick note because it seems like a lot of people are looking for this. I was dealing with a badly behaving feature but had to find all the places it was installed on a fairly ornate farm. Here’s what I finally came up with:

Get-SPSite -limit ALL | Get-SPWeb -limit ALL | foreach{ $_.features[“GUID”] } | select Parent

This will give you the site names where the feature is installed. The GUID is the ID of the feature. It could use some more work, specifically returning status and URL, but this will get you 90% of the way there.

Rename SharePoint Site Collections

Resuming my renaming spree, we’re going to take a look at how to rename SharePoint site collections. Our first stop is working with Site Collections. Site collections don’t have a name per se, but they do have a URL, and it’s something that folks often want to change. As of SharePoint 2010, there isn’t a direct way to change the URL for a site collection, so the accepted method is to back up the site collection, delete the existing collection, then restore the collection with the new URL. Kind of a pain, but better than starting from scratch…

Backup-SPSite URL –Path path [-Force] [-NoSiteLock] [-UseSqlSnapshot]

Force: Overwrite the backup file if it already exists

NoSiteLock: Forces the site collection to remain in read/write mode during the backup

UseSqlSnapshot: If supported, creates a SQL Server database snapshot, then runs the backup from that snapshot. This reduces the chances of corruption of the backup.

So we can list the current site collections with Get-SPSite:

PS C:\Users\Administrator> get-spsite


Then we hook a site collection using the –id parameter:

PS C:\Users\Administrator> $site=get-spsite -id http://gemini2010/sites/mydemosite

This way we can verify that we have the right site collection:

PS C:\Users\Administrator> $site


Once we’re sure we have the right site collection, we can back it up with the PowerShell command:

PS C:\Users\Administrator> Backup-SPSite $site -Path "c:\temp\mydemosite.bak"

You’ll find the .bak file in the path you pointed it to. Now deleting a site collection is far, far too easy:

PS C:\Users\Administrator> Remove-SPSite $site
Are you sure you want to perform this action?
Performing operation "Remove-SPSite" on Target "http://gemini2010/sites/MyDemoSite".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "Y"):y

PS C:\Users\Administrator>

If you have a large site collection, you can use the –GradualDelete parameter to indicate that SharePoint should delete the site collection gradually to reduce the load on the system. Once this completes, if you try any of the URLs in the site collection, you’ll get a 403 Forbidden error.

Finally, we restore the backup, using our new URL.

PS C:\Users\Administrator> Restore-SPSite http://gemini2010/sites/MyNewDemoSite -Path c:\temp\mydemosite.bak

Are you sure you want to perform this action?
Performing operation "Restore-SPSite" on Target "http://gemini2010/sites/MyNewDemoSite".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):y

PS C:\Users\Administrator>

Note that you have to restore the Site Collection to a top-level site. Once you run this, your site collection will be back at the new URL, with all subordinate sites mapped appropriately.

Next time we’re going to muck about with renaming sites themselves.

Rename Alternate Access Mappings

Another chapter in renaming everything in SharePoint…

If you’re looking for a good overview of what an alternate access mapping is, check out Edwin’s article on configuring alternate access mappings.

When you start creating an alternate access mapping, the collection takes the name of the web application. However, this may not be what you want – the context when working with web applications is different than the AAMs. In addition, once the AAM is created, if you rename the web application the name of the AAM isn’t changed.

The name is actually the name of the AAM collection. When you look at the alternate access mappings, each URL is a mapping; the mappings for a web application are a collection, and that’s where the name in the selector comes from, as indicated below.


The AAM collection is a property of the Web Application, so to get a handle on it:

$sp=get-spwebapplication http://sitename

Or, to list web applications and fetch one by ID:

PS C:\Users\Administrator> get-spwebapplication | select displayname, id

DisplayName                             Id
-----------                             --
SharePoint - 16275                      584e9d9c-e652-4b1d-9d77-3ffd033fe14a
SharePoint - 80                         51ca3304-3629-4fe7-9429-638db13ae225

PS C:\Users\Administrator> $sp=get-spwebapplication -id 51ca3304-3629-4fe7-9429-
PS C:\Users\Administrator> $sp

DisplayName                    Url
-----------                    ---
SharePoint - 80                http://gemini2010/

Now that you have the web application, the AAM collection is in the property “alternateurls,” which you can hook like this:

$auc = $sp.alternateurls

Now the $auc variable has the alternate access mapping collection, and it’s simple to rename it:

$"Primary Corporate Website"





If you have a number of SharePoint sites to work with, this is much easier than trying to figure out if the intranet workflow site is “SharePoint – 2580” or “SharePoint – 3740”