Solved

How can I see a list of sharepoint 2010 sites

Posted on 2011-03-07
6
363 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:jayklynn
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:ThatSharepointGuy
ID: 35062346
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

./ShowSites.ps1

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.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

## 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;
		}
	$site.Dispose();
}

Open in new window

0
 
LVL 6

Expert Comment

by:ThatSharepointGuy
ID: 35062401
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.

0
 

Author Comment

by:jayklynn
ID: 35069927
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
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Accepted Solution

by:
ThatSharepointGuy earned 500 total points
ID: 35070960
Jayklynn,

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...

https://SharePointServer/SiteCollection1
https://SharePointServer/SiteCollection2
https://SharePointServer/SiteCollection3
https://SharePointServer/SiteCollection4
https://SharePointServer/SiteCollection5

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!
0
 

Author Comment

by:jayklynn
ID: 35071800
That worked perfectly.  Thank you.
0
 
LVL 6

Expert Comment

by:ThatSharepointGuy
ID: 35072473
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!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently came across an issue with a MOSS 2007 deployment where access into some sub-sites were denied, even for the MOSS farm administrators. A bit of background to the setup of this MOSS farm; this was a three server setup, consisting of a fr…
I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now