Saturday 15 February 2020

PS: SharePoint Update the Document Set


Content types that are available to this Document Set have been added or removed. Update the Document Set.

Sometimes when we click on a document set and within the same we see a yellow line reading
Content types that are available to this Document Set have been added or removed. Update the Document Set.
The reason behind it is that this document set is not created using the OOB way but using some kind of code practices. Ideal way to create document set is by using

– DocumentSet.CreateDocumentSet

which sets the docset_LastRefresh property.

Also if you are using any custom code to create the Document Set then during creation of the doc set sometime properties not setup properly so for this type of case you can easily update the doc set for the below script :-

 Add-PsSnapin Microsoft.SharePoint.PowerShell
  $webUrl="http://sitecoll/site/ABC"
    $web = Get-SPWeb -Identity $webUrl
    $lib=$web.Lists["ABC"]
       foreach($item in $lib.Items | Where-Object {$_.Folder -ne $null -and $_.ID -eq "18"})
        {
         Write-Host "Provisioning " $item.Name
         Write-Host $item.Folder.Properties["docset_LastRefresh"]
            if ($item.Folder.Properties["docset_LastRefresh"] -eq $Null) 
            {
                Write-Host "Provisioning " $item.Name   -ForegroundColor Green
                $ds = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::GetDocumentSet($item.Folder)
                $ds.Provision()
            }
        }
    $web.Dispose()


In case, if you are not sure about the last refresh for document set happened or not then just update the document set without condition check:-

Add-PsSnapin
Microsoft.SharePoint.PowerShell
  $webUrl="http://sitecoll/site/ABC"
    $web = Get-SPWeb -Identity $webUrl
    $lib=$web.Lists["ABC"]
       foreach($item in $lib.Items | Where-Object {$_.Folder -ne $null -and $_.ID -eq "18"})
        {
         Write-Host "Provisioning " $item.Name
         Write-Host $item.Folder.Properties["docset_LastRefresh"]
                Write-Host "Provisioning " $item.Name   -ForegroundColor Green
                $ds = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::GetDocumentSet($item.Folder)
                $ds.Provision()
        }
    $web.Dispose()

No comments:

Post a Comment