Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I see a list of sharepoint 2010 sites

Posted on 2011-03-07
6
Medium Priority
?
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 6

Accepted Solution

by:
ThatSharepointGuy earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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