SharePoint 2010 Powershell – Detailed Site Overview


It’s not the first time that one of our customers ask us for a complete overview of there intranet. The Content & Structure page is nice and easy but cumbersome while navigation.

I wrote a powershell script to accomplish this. It was time consuming but not that difficult, just enumerating all webs, lists, permissions, fields, views…

the output of the script gives you 2 xml files:

File 1: the execution time of the script is combined with the filename (for historical purposes)

File 2: just a normal fixed filename, very handy for reporting!

The actual powershell script:


# Powershell: Generated Site Overview.
#
# Copyright (c) 2011 Aurelium
# Dual licensed under the MIT and GPL licenses:
# http://www.opensource.org/licenses/mit-license.php
# http://www.gnu.org/licenses/gpl.html
# @author: Steven Derveaux (http://www.aurelium.be)
# @version: 1.0 - 2012/05/23

param([string]$url = “xml”, [switch]$help)

function GetHelp() {
$HelpText = @”

DESCRIPTION:
NAME: SP-GetSiteStructureList
Enumerates through a Site Collection in the farm and lists all libraries to a csv file

SYNTAX:

SP-GetSiteStructureList -url http://yoursite

“@
$HelpText

}

function EnumSiteStructure($url){
[xml]$xml = “”
$date = Get-Date

$site = new-object Microsoft.SharePoint.SPSite ($url)
$web = $site.OpenWeb()
$filename = “Structure_” + $web.Url.Replace(“http://”,””).Replace(“/”,”_”) + “.xml”;
$filename2 = “Structure_” + $web.Url.Replace(“http://”,””).Replace(“/”,”_”) + “_” + $date.ToString(“yyyyMMdd_hhmmss”) + “.xml”;

$attr = $xml.CreateAttribute(“ScriptRun”)

$attr.Value = $date.ToString(“dd/MM/yyyy hh:mm:ss”)
[Void]$xml[“Websites”].SetAttributeNode($attr)

foreach ($web in $site.AllWebs){

$xmlWeb = $xml.CreateElement(“Website”)

$attr = $xml.CreateAttribute(“Title”)
$attr.Value = $web.Title
[void]$xmlWeb.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“Url”)
$attr.Value = $web.Url
[void]$xmlWeb.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“HasUniqueRoleAssignments”)
$attr.Value = $web.HasUniqueRoleAssignments
[Void]$xmlWeb.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“Created”)
$attr.Value = $web.Created
[Void]$xmlWeb.SetAttributeNode($attr)

$xmlRoleAssignments = $xml.CreateElement(“RoleAssignments”)

foreach ($roleAssignment in $Web.RoleAssignments){
$xmlRoleAssignment = $xml.CreateElement(“RoleAssignment”)
$attr = $xml.CreateAttribute(“Member”)
$attr.Value = $roleAssignment.Member
[Void]$xmlRoleAssignment.SetAttributeNode($attr)

foreach($roleBinding in $roleAssignment.RoleDefinitionBindings){
if ($roleBinding.Name -ne “Limited Access”){
$xmlRoleBinding = $xml.CreateElement(“RoleBinding”)

$attr = $xml.CreateAttribute(“Name”)
$attr.Value = $roleBinding.Name
[Void]$xmlRoleBinding.SetAttributeNode($attr)
[Void]$xmlRoleAssignment.AppendChild($xmlRoleBinding)
}
}
[Void]$xmlRoleAssignments.AppendChild($xmlRoleAssignment)
}

[Void]$xmlWeb.AppendChild($xmlRoleAssignments)

$xmlLists = $xml.CreateElement(“Lists”)

foreach ($list in $web.Lists){
if ($list.Hidden -eq 0){

$xmlList = $xml.CreateElement(“List”)
$attr = $xml.CreateAttribute(“Title”)
$attr.Value = $list.Title
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“BaseType”)
$attr.Value = $list.BaseType
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“ContentTypesEnabled”)
$attr.Value = $list.ContentTypesEnabled
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“OnQuickLaunch”)
$attr.Value = $list.OnQuickLaunch
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“HasUniqueRoleAssignments”)
$attr.Value = $list.HasUniqueRoleAssignments
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“EnableVersioning”)
$attr.Value = $list.EnableVersioning
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“EnableMinorVersions”)
$attr.Value = $list.EnableMinorVersions
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“EnableModerations”)
$attr.Value = $list.EnableModerations
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“ID”)
$attr.Value = $list.ID
[Void]$xmlList.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“ItemCount”)
$attr.Value = $list.Items.Count
[Void]$xmlList.SetAttributeNode($attr)

$xmlRoleAssignments = $xml.CreateElement(“RoleAssignments”)

foreach ($roleAssignment in $list.RoleAssignments){
$xmlRoleAssignment = $xml.CreateElement(“RoleAssignment”)
$attr = $xml.CreateAttribute(“Member”)
$attr.Value = $roleAssignment.Member
[Void]$xmlRoleAssignment.SetAttributeNode($attr)

foreach($roleBinding in $roleAssignment.RoleDefinitionBindings){
if ($roleBinding.Name -ne “Limited Access”){
$xmlRoleBinding = $xml.CreateElement(“RoleBinding”)

$attr = $xml.CreateAttribute(“Name”)
$attr.Value = $roleBinding.Name
[Void]$xmlRoleBinding.SetAttributeNode($attr)
[Void]$xmlRoleAssignment.AppendChild($xmlRoleBinding)
}
}
[Void]$xmlRoleAssignments.AppendChild($xmlRoleAssignment)
}

[Void]$xmlList.AppendChild($xmlRoleAssignments)

$xmlFields = $xml.CreateElement(“Fields”)

for ($i=0; $i -lt $list.Fields.Count; $i++){
if ($list.Fields[$i].Hidden -eq 0){
$xmlField = $xml.CreateElement(“Field”)
$attr = $xml.CreateAttribute(“Title”)
$attr.Value = $list.Fields[$i].Title
[Void]$xmlField.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“Type”)
$attr.Value = $list.Fields[$i].Type
[Void]$xmlField.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“Group”)
$attr.Value = $list.Fields[$i].Group
[Void]$xmlField.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“Required”)
$attr.Value = $list.Fields[$i].Required
[Void]$xmlField.SetAttributeNode($attr)
[Void]$xmlFields.AppendChild($xmlField)
}
}
[Void]$xmlList.AppendChild($xmlFields)
$xmlViews = $xml.CreateElement(“Views”)

for ($i=0; $i -lt $list.Views.Count; $i++){
$xmlView = $xml.CreateElement(“View”)

$attr = $xml.CreateAttribute(“Title”)
$attr.Value = $list.Views[$i].Title
[Void]$xmlView.SetAttributeNode($attr)

$attr = $xml.CreateAttribute(“Query”)
$attr.Value = $list.Views[$i].Query
[Void]$xmlView.SetAttributeNode($attr)

foreach ($viewField in $list.Views[$i].ViewFields){
$xmlViewField = $xml.CreateElement(“ViewField”)
$xmlViewField.InnerXml = $viewField
[Void]$xmlView.AppendChild($xmlViewField)
}

[Void]$xmlViews.AppendChild($xmlView)
}

[Void]$xmlList.AppendChild($xmlViews)
[Void]$xmlLists.AppendChild($xmlList)
}
[Void]$xmlWeb.AppendChild($xmlLists)
}
[Void]$xml[“Websites”].AppendChild($xmlWeb)
$web.Dispose()
}

$site.Dispose()

$xml.Save(“C:\Aurelium\Powershell\” + $filename)
$xml.Save(“C:\Aurelium\Powershell\” + $filename2)
}

if($help) { GetHelp; Continue }
if($url) { EnumSiteStructure -Url $url}
else { GetHelp; Continue }

 

Advertisements
This entry was posted in Sharepoint and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s