Thursday, 21 October 2010

Change SharePoint list settings using PowerShell - Part 2: Advanced Settings

This article follows on from Part 1 last week, where I detailed how to change the General and Versioning Settings of a SharePoint list or document library with PowerShell.

This part covers changing the Advanced Settings of a list. As a recap, you can use the following script to change the settings of a specifically named list on each site in the site collection. In the example below, we are changing the settings of a document library called “Shared Documents” on each site in the “http://portal” site collection:

#Change these variables to your site URL and list name
$site = Get-SPSite http://portal
$listName = "Shared Documents"

#Walk through each site in the site collection
$site | Get-SPWeb | ForEach-Object {

#Get the list in this site
$list = $_.Lists[$listName]

#Make the list changes

#Update the list
$list.Update()
}

#Dispose of the site object
$site.Dispose()

The table below shows the Advanced Settings we can change, with snapshots of the same settings from the list admin UI. To use any of these settings from the table, copy them into the script above, underneath the “#Make the list changes” line:

Document Template
(document libraries only)
image
The following set of commands will upload a new document template from a path on your computer or network (UNC) path and change the document template setting on the list:

#Upload new document template file from computer
$newTemplateFile = Get-ChildItem "C:\LocalPath\Test Document.dotx"
$templateFolderPath = $_.Url + "/" + $list.RootFolder.Url + "/Forms"
$templateFolder = $_.GetFolder($templateFolderPath)
$uploadPath = $templateFolder.Url + "/" + $newTemplateFile.Name
$spNewTemplateFile = $templateFolder.Files.Add($uploadPath, $newTemplateFile.OpenRead(), $true)

#Change list setting to the template file uploaded
$list.DocumentTemplateUrl = $uploadPath

Note: If you are running this script on a single site rather than in bulk on each site in the site collection, change the $_ references above to the variable you have assigned to the site – e.g., $web

Opening Documents in the Browser
(document libraries only)
image
There are a couple of settings affecting these options. Use the following commands to set one of the first two options:

#Open in the client application
$list.DefaultItemOpen = "PreferClient”

#Open in the browser
$list.DefaultItemOpen = "Browser"

If you want to set the “Use the server default” option, use the following command:

$list.DefaultItemOpenUseListSetting = $false
Custom Send To Destination
(document libraries only)
image
For this option you have to set a destination name and URL of the custom Send To location:

$list.SendToLocationName = "Home Site"
$list.SendToLocationUrl = "http://Portal/Shared Documents"

Item-level Permissions
(lists only)
There are two options on this section, depending on whether you are looking to restrict user read or write access.

Read access
This setting uses a numerical value to determine which option is set:

Read all items = 1
Read items that were created by the user = 2

image
For example, the following command would be used to configure this setting to “Read items that were created by the user”, as pictured above:

$list.ReadSecurity = 2

Create and Edit access
This setting also uses a numerical value to set the option desired:
Create and edit all items = 1
Create items and edit items that were created by the user = 2
None = 4

image
For example, the following command would be used to configure this setting to “None”, as pictured above:

$list.WriteSecurity = 4
E-Mail Notification
(task and issue based lists only)
image
This command will enable the “Send e-mail when ownership is assigned” option:

$list.EnableAssignToEmail = $true
Attachments
(lists only)
image
The following command will disable attachments on the list:

$list.EnableAttachments = $false
Folders image
Use the following line to disable the “New Folder” command on list and library menus:

$list.EnableFolderCreation = $false
Search image
Careful with the wording on this one, as setting it to $true will set it to No in the UI, as pictured above:

$list.NoCrawl = $true
Offline Client Availability image
Similar to the way the Search option works above, setting this one to $true will set it to No in the UI, as pictured above:

$list.ExcludeFromOfflineClient = $true
Site Assets Library
(document libraries only)
image
This setting will switch the document library to be a site assets library:

$list.IsSiteAssetsLibrary = $true
Datasheet image
Careful with the wording on this one also, as setting it to $false will set it to Yes in the UI, as pictured above:

$list.DisableGridEditing = $false
Dialogs image
Similar to the way the Datasheet option works above, setting this one to $true will set it to No in the UI, as pictured above:

$list.NavigateForFormsPages = $true

In Part 3 of this series, I’ll cover a few extra settings you can configure on a list with PowerShell, including some options hidden from the UI…

15 comments:

  1. Do you have part3 already available?

    ReplyDelete
  2. Not yet - having a few weeks off so probably 2011 now I'm afraid

    ReplyDelete
  3. Phil
    Nice Post, Is there a way to loop it and change the default open behavior for all document libraries not just for document libraries called "Shared Document"? I tried to do

    $web.getlistoftype("DocumentLibrary")

    but I cannot set a defaultitemopen this way. Any help is appreciated.

    ReplyDelete
  4. Hi Avinash,

    You could enumerate through all lists and run a check on their type using the following IF statement:

    if ($list.BaseType -eq "DocumentLibrary")

    ReplyDelete
  5. Hi again Avinash,

    Just remembered that I do a similar operation to the one you requested on the second script listed in this article: http://get-spscripts.com/2010/11/add-and-remove-site-content-types-from.html

    For example:

    #Go through each document library in the site
    $_.Lists | where { $_.BaseTemplate -eq "DocumentLibrary" } | ForEach-Object {

    write-host "Checking list:"$_.Title

    #Do whatever you need to do here

    }

    ReplyDelete
  6. Great site; When discussing PowerShell i often reference you site!

    Quick question regarding this solution: Is there an easy way to tell Word & Powerpoint to open in client applications while having Visio and Excel continue to open in the browser?

    ReplyDelete
  7. Great post! You saved my life!

    ReplyDelete