Tuesday, 11 March 2014

SharePoint 2010 PowerShell script to create a Visio Site Map

The script below creates a csv file output that can be used in Visio 2010 to create a site map. The usage is:

.\get-webinventory.ps1 -siteurl <url of site> | export-csv -NoTypeInformation -Path<file location>


To get Visio chart perform the following:

1.Log on to the SharePoint Server
2.Open Powershell, cd to script locationRun .\get-spwebinventory.ps1 -url <siteurl> | export-csv -NoTypeInformation -Path <csv file>
3.Copy the output file to your workstation with Visio 2010 installed
4.Open Visio and create an Org Chart
5.Click the Org Chart tab and click Import
6.Click "Next", "Text or Excel File", Browse to output file csv, Next
1.Name: ID
2.Reports to: ParentID
3.First Name: RelativeUrl
7.Next
8.Display Fields: RelativeUrl
9.Next
10.Move all columns to Shape Date Fields
11.Next
12.Click "I want to specifiy....."
13.Next, Finish

Once the chart has been create, subordinate format can be changed by right clicking the parent and choosing "Arrange Subordinates"




Script: get-webinventory.ps1


# COMMENTS: This script will be used to get a list of lists and counts for
# a site url. It will traverse the URL and go though the subsites
# as well.
#
# ————————————————————————
#

param ($url)

Function Get-WebSiteInventory{
    Param([string]$url)
    $site = get-spsite $url
    foreach ($web in $site.AllWebs) {
        $LastModified = $Web.LastItemModifiedDate
        $SnapShot = (get-date)
        $LastUpdate = ($SnapShot – [datetime]$LastModified)
        [uri]$weburl = $web.url
        $relativeurl = ($web.url).replace(($web.site.url),"")
        $data = @{
            Site = $web.title
            URL = $web.url
            "RelativeURL" = $relativeurl
            ID = $web.ID
            ParentID = $web.ParentWebID
            Last Modified = $web.LastItemModifiedDate
            Snaphost Date = $SnapShot
            Last Update = $LastUpdate.Days
            "HasUniquePerms" = $web.HasUniquePerm
            "Owners Group" = $web.AssociatedOwnerGroup
            "Group Count" = ($web.groups).count
        }
        New-Object PSObject -Property $data
        $web.Dispose();
    }
    $site.Dispose()
}

If ((Get-PsSnapin |?{$_.Name -eq "Microsoft.SharePoint.PowerShell"})-eq $null)
{
    $PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
}

Get-WebSiteInventory $url 

Monday, 10 March 2014

SharePoint 2010 - Adding lookup additional columns for choice column type

SharePoint Lookup columns are great, and with SharePoint 2010 you can bring over additional columns from the lookup list. But these are limited to:

Single Line
Number
Currency

The "Choice" column type isn't supported. But we can use a combination of calculated columns and content types to get around this. The calculated column will take the Choice column and create a single line calculated column. The content type will "hide" this calculated column so it doesn't appear on forms. Note that this only works for Choice column types with single selection (multiple selections aren't supported)

So in this example, consider two lists

1. Countries

The list that will be looked up. Contains three columns - Name (single line), Continent (choice) and language (choice)

2. Offices

The list that will contain a lookup to Countries, and bring over Continent and language.

Steps

1. On the SharePoint site where the two lists are located.
2. Go to "Countries" list settings, Advanced Settings, "Allow management of content types"
3. On the "Contries" list settings, Create a new column called ":Continent" as a calulcated field. Use this formula

=IF(Continent="","",Continent)

This will stop "0" appearing if the Continent choice column has no value.
IMPORTANT: UNTICK "Add to all content types" and "Add to default view" before saving. This will stop this calculated column appearing in forms on this list.

4. Do the same (Step 3) for the Language choice column
5. Go to "Offices" list settings, Add a lookup column pointing to "Countries". You should now see the calculated columns (those with a ":" at the start for you to select). If you have normal single line columns you are bringing over, you can select these too. The difference is that the calulated columns have an additional ":" in their name. I.E.

Countries:Name, Countries::Continent, Countries::Language

It isn't too noticeable in the view ot form. And that's it!