Create A Visio SharePoint Site Map And Document Count (SharePoint 2007, SP2010, & SP2013)

DougApplication Development Manager
One of the most challenging things I've run into as a SharePoint consultant is creating a visual sitemap of a SharePoint environment.  Visual maps are so much more effective when showing clients what their environment looks like and how it can be optimized when performing a migration, security review, or consolidation effort.  My inspiration for publishing this article is hoping it will provide others in the same position an easy way to get a visual overview of their SharePoint environment.
1.png*NOTE: The yellow colored objects were manually set. I try to get only 1 row of pages in Visio. If any go beyond 1 row, I put them in a different Visio sheet and uniquely identify that node by changing the color.
Run this PowerShell script.
  • By default it uses the local SharePoint environment so it should be run on the SP server itself.
  • If you want to specify a specific WebApplication, you can modify the script. 
  • This was written for WSS 3.0 and MOSS 2007 to run using PowerShell 1.0 because that's what many companies are migrating from.  For 2010 and 2013 I'm aware there are optimizations that could be made to the script
The script is commented but is pretty straight forward.
#clear the PowerShell window
                      #Set or reset default properties
                      $ReportPath = "SPSiteReport.csv"
                      #Load the PowerShell commandlets for SharePoint using PowerShell 1.0 and MOSS 2007 compatibility
                      $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
                      #Print the header in the resulting file
                      $Header = " `tCount`tTitle`tURL`tType`tID`tParent"
                      Out-File -inputobject $Header -filepath $ReportPath -Force
                          foreach ($spService in $farm.Services) {
                              if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {
                              foreach ($webApp in $spService.WebApplications) {
                                  if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }
                                  foreach ($site in $webApp.Sites) {
                                      foreach ($web in $site.AllWebs) {
                      					foreach ( $List in $Web.Lists )
                      						#Get the count of items in the current list
                                              $Count = $Count + ($List.Folders.Count + $List.Items.Count)
                      						Write-Progress -activity "Inventorying items. . ." -status "Processing items in Site> $web - List> $list"
                      					#Output the result of the current list
                      					$Result = " " + "`t" + $Count + "`t" + $Web.Title + "`t" + $Web.URL + "`t" + $List.BaseType + "`t" + $web.ID + "`t" + $web.ParentWebID
                      					Out-File -inputobject $Result -filepath $ReportPath -append
                      					#Reset the item counter

Open in new window

Short and simple but VERY effective. If you don't need document counts, you can comment out the inner-most foreach loop that spins through each list.  However, you'll have to also modify the $Header (at the top where the column headers are written) and $Result (after the inner-most foreach where the values are saved) to remove the Count value.  
After running the script, you will have a csv file that will contain the information exported from the script. Now, open MS Visio and create a new Organizational Chart. I'm using Visio 2013.
Since we have the CSV file already, use the option for "Information that's already stored in a file or database"
3.pngSelect the text document
Browse to the file that the script created
Here, you want to have the fields setup as follows:
Name: ID
Reports To: Parent
First Name: Title
This takes the columns it found in the csv file and is asking you how it is organized hierarchically. The ID and Parent are the GUIDs of the sites showing the lineage. The First Name is the name of the respective site
These display fields are good to get setup the first time. I don't use the Parent or ID fields in my display because they are just GUIDs. I order the displayed fields to show Title, Count, Type, and finally URL:
7.pngBecause you're displaying the above fields, you have to also give them a display shape. Also, because the ID is required, it too will have a place on the chart, thus overriding the previous step (with sarcasm... "thanks Microsoft").
You probably don't have nor want to include pictures of each site in the chart and actually, we'll be hiding the picture field once this is done.
9.pngThis step is sometimes tricky. Most of the time I can just hit "Finish" and it will build the sitemap perfectly. However, there were occasions where I had to just hit the dropdown and then press finish.
I generally choose the second option because Visio will build separate sitemaps for different subsites. However, if you want to have the entire sitemap built on one sheet for you to split if necessary, select the first option. 
10.pngWhen I had to click the dropdown, I was given this dialog box. Press "Yes"
Visio will now build the sitemap. 
To remove the empty picture object and gain more real estate for the text, select all the shapes (ctrl+a), right click on one of the shapes and select, "Picture" --> "Hide Picture" or "Delete Picture"

There you go!  A beautiful site map of your SharePoint environment.
DougApplication Development Manager

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.