Powershell tip for updating document sets

If you’re using the handy Document Sets feature in SharePoint 2010 you may run in to a small issue where you make some changes to your document set (e.g., add/remove content types from the allowed contents). When you do this, and push changes down to existing document sets, you’ll see a little yellow bar appear on each document set with the message

“Content Types that are available to this Document Set have been added or removed. Click here to update the Document Set.”

The reason is that the document set refresh date needs updating. Quite why SharePoint can’t manage this for you, is beyond me, but nevertheless, if you do click the yellow bar, it disappears. But it still remains for all your other document sets. Irritating. So here’s how to remove the little yellow bar with the message using Powershell. The neatest way is just to provision the document set.


Powershell script

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.DocumentManagement")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$weburl = "http://yourURL"
$web = Get-SPWeb $weburl
$lib = $web.Lists["Document Library Name"]
$lib.Items | Where-Object {$_.Folder -ne $null} | ForEach-Object {
{
 Write-Host "Provisioning " $item.Name
 $ds = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::GetDocumentSet($item.Folder)
 $ds.Provision() 
}

And that ought to do it.

Original inspiration from here and here

Post was updated based on Rod’s comments below. Also what is poor in the script is it uses $lib.Items directly which is BAD on a large library. You would typically execute a paged request to process large libraries. If you are running this on a large library then be prepared for memory issues.

11 Comments

  1. What version of SP? What other debugging have you done? I guess it’s something to do with the way your WF creates the DS… are they setting the content type correctly?

    Use the script to target one of your new objects directly and check if the .Folder property is null or not.

    Alternatively update the script so that rather than targeting that, it targets your specific Content Type.

  2. Tried the scripts and has no effect on my problem document sets.
    these sets were all built via a workflow.
    i made one doc set via New Document Set command from the ribbon. This script does see that one set

  3. Hi Ingo. I think that depends what version of SharePoint you’re accessing. SP2013 has a DocumentSet class in the Client API. There’s no provision method but I would guess loading a DS and then calling Update on it might achieve the same thing. (Not sure.)

    There doesn’t appear to be a corresponding class for the Client API in SP2010.

  4. Am not sure am looking it right,
    I picked two document sets and the doc sets werent updated in it and it was showing the msg.
    i went into the log , searched for this doc set numbers, i cant find it. not sure if am doin it right.

  5. yes, i did, i tried both and i get the messages as provisioning …. with all the doc set numbers but it dint do anything after chking by opening each doc set invidiually

  6. Even after running the script with no error i still see the message “Content types that are available to this Document Set have been added or removed. Update the Document Set.” not sure whats next

  7. did some research and the foreach-object method is much more memory efficient and quicker (for this type of usage)
    than foreach – here is the modified script using foreach-object instead of foreach.

    This script doesnt consume more the 600MB ram whereas the original one using foreach used all 8GB on the test
    server and then hung.

    I have also included a logging element to capture how long the script takes to run

    [void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.DocumentManagement”)
    [void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    $timestamp = Get-Date -format “dd.MM.yyyy-HH.mm.ss”
    start-transcript -path d:downloadscripts$timestamp-DocSetContent.log
    $weburl = “http://fqdn/site_name/”
    $web = Get-SPWeb $weburl
    $lib = $web.Lists[“Library Name”]
    $lib.Items | Where-Object {$_.Folder -ne $null} | ForEach-Object {
    Write-Host “Provisioning ” $_.Name
    $ds = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::GetDocumentSet($_.Folder)
    $ds.Provision()
    }
    stop-transcript

  8. Thanks for the post, it was just what we were looking for. Unfortunately when the script is run against a library with 17,000 doc sets it consumes all available memory and then hangs – this is a know problem with the foreach method – I have posted onto a couple of forums looking for a solution – do you have any ideas?

Leave a Reply

Your email address will not be published.


*