• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

How can I see a list of sharepoint 2010 sites

I am very new to Sharepoint 2010.  I have never really run a previous version.  We installed a nonproduction instance to begin testing.  I have created a couple of test site and subsites.  I am curious to see what is the best way to see a listing of urls for the existing sharepoint sites and subsites.  Thank you.
  • 4
  • 2
1 Solution
Hello Jayklynn,

If you open the SharePoint 2010 Management Shell (PowerShell), add the code that I've pasted into a text file, save it as "ShowSites.ps1", and in the management shell browse to where it's saved and type


It should output all of your site collections and subsites in a quick list for you.

You can tweak it to look better, but if you're just looking for a listing of sites, this is a very simple method to use.

## Get primary web applicaiton (not central admin / not MySites).
$webApp = Get-SPWebApplication "MOSS_Dev"

## Iterate through all SPSite objects within the SPWebApplication.
foreach ($site in $webApp.Sites)
	## Get the total number of SPWebs for each SPSite.
	for($i=0; $i -lt $site.AllWebs.Count; $i++)
			Write-Output $site.AllWebs[$i] | Select Url;

Open in new window

My apologies for posting again, but I find that an Edit button is lacking here at E.E.!  

In the code above, where it says "$webApp = " replace the "MOSS_Dev" with the Web Application hosting your SharePoint sites.  

To find this, you can log in to Central Administration, Click on "Application Management", Click "Manage Web Applications", and this should show all of the web applications created on your server.

jayklynnAuthor Commented:
Thank you.  I went through the steps and I was able to run the script, however, it did not give me the output I was looking for.  I have attached a jpg of the screen.  Perhaps I am doing something wrong or I am missing a switch or something. Thanks again.

Power Shell Output
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Perhaps you do not have any sites created?  I'm not sure, as the script works for me.  Did you "select all" in the code window up top, and are sure you aren't missing anything?

It should give you output similar to my attached screenshot (I had to remove the important part of the URL for privacy concerns, so it's got a big black square in the middle...haha).

 PowerShell Screenshot
Another thing you can try is to go to the SP Powershell console and type this:

$webApps = Get-SPWebApplication; $webApps

Open in new window

This code just takes the output listed below and stuffs it into the $webApps variable so you can use it later.  It should output something akin to:

DisplayName   URL
---------------    -----
WebApp1        https:///mySPServer
WebApp2        https:///mySPServer:8080/

So look at those, and determine which one hosts your sites.  If this is a new installation, chances are you're only going to have one or two.  One will be the "MySites" host (if you've configured it) and (if it's there) will be easily identifiable.  You want the web application hosting your sharepoint stuff.  It might just be called "SharePoint - 80" in most cases.  You'll also know this, as when you create a site collection you  have the ability to choose which web application it goes under.

Regardless, when you know which Web Application is hosting your sites, type the following:
 $webApp = Get-SPWebApplication "[b]NAME_OF_WEB_APPLICATION[/b]"

Open in new window

Be sure to replace the "NAME_OF_WEB_APPLICATION" with the name of your web app, like "SharePoint - 80" (in quotes)

So now you have a list of all Web Applications stored in $webApps variable, and you have your SPECIFIC Web Application hosting your SP sites in the $webApp variable (no "s" at the end).  

Type this:
foreach ($site in $webApp.Sites) { Write-Output $site.URL }

Open in new window

Which should output something like...


Now, at this point you know that it's giving you a list of your site collections, so that part works.  To go and have it print out all subsites (spWeb objects) under each site collection (spSite objects), type this:

foreach ($site in $webApp.Sites) { for($i=0; $i -lt $site.AllWebs.Count; $i++) { Write-Output $site.AllWebs[$i] | Select Url; }  $site.Dispose(); }

Open in new window

All on one line.  You don't have to change anything in it at all, as long as the $webApp variable that you set above contains the correct web application.  If it doesn't, this will still return any sites on the web app, but you'll know they're the wrong sites (because they won't match what you're looking for...so if you had a PublicReleations site collection and it doesn't show up, you're probably on the wrong web application).

Let me know if that helps.  The code is exactly the same, minus the comments.  And this way, you're typing each little bit into the SP PowerShell window so you can see what's working and what's not working.  

Keep me updated, and good luck!
jayklynnAuthor Commented:
That worked perfectly.  Thank you.
Awesome, you're welcome!  You can easily go online and find out how to have Powershell output stuff to Notepad or Excel.  Personally I just use Notepad, as I have scripts that will go through and read my outputs (not for site listings, but other things that I return like group memberships and whatnot).

Use the help file for Out-File to get a head's up on that!  
Get-Help Out-File -Full

Open in new window

Good luck in your adventures!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now