2

I have 200 site collections that need to perform the following tasks:-

A. At the Site Collection Administration - Record Declaration Settings

  1. Set Record Restriction to Block Delete
  2. Set Record Declaration Availability to Available in all locations by default
  3. Set Declaration Roles - The declaration of records can be performed by: All list contributors and administrators
  4. Set Declaration Roles - Undeclaring a record can be performed by - Only list administrator

B. At the Document Library Settings - Record Declaration Settings

  1. Set manual record declaration availability to Always allow the manual declaration of records

How can I do the above tasks via Powershell. Thanks

2

This is how "point Always allow the manual declaration of records" can be done:

    $web = get-spweb http://TestWeb
    $list = $web.Lists["ListName"]
    $list.RootFolder.Properties["ecm_IPRListUseListSpecific"] = "True"
    $list.RootFolder.Properties["ecm_AllowManualDeclaration"] = "True"
    $list.RootFolder.Update()
  • Use the following line of code to deselect the option "Automatically declare items as records when they are added to this list": [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::ConfigureListFor‌​AutoDeclaration($list, $false); – H A Jan 30 '15 at 18:57
1

Here is the full script for the above task

function Set-Feature([Microsoft.SharePoint.SPSite] $Site)
{
    $feature = Get-SPFeature InPlaceRecords
    Enable-SPFeature $feature -Url $Site.Url
}

function Set-Audit ([Microsoft.SharePoint.SPSite] $Site)
{
    $Site.Audit.AuditFlags=[Microsoft.SharePoint.SPAuditMaskType]::None 
    $Site.Audit.Update()

    $auditMask = [Microsoft.SharePoint.SPAuditMaskType]::View -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::Update -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::CheckIn -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::CheckOut -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::Delete -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::Undelete -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::Copy -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::Move -bxor
                 [Microsoft.SharePoint.SPAuditMaskType]::SecurityChange 
    $Site.TrimAuditLog = $false
    $Site.Audit.AuditFlags = $auditMask
    $Site.Audit.Update()
}

function Set-ContentTypePublishingHub([Microsoft.SharePoint.SPSite] $Site)
{
    if($Site.RootWeb.Properties.ContainsKey("MetadataTimeStamp"))
    {
        $Site.RootWeb.Properties["MetadataTimeStamp"] = [string]::Empty
        $Site.RootWeb.Update()
    }
}

function Set-RecordDeclarationSetting([Microsoft.SharePoint.SPSite] $Site)
{
    if($Site.RootWeb.AllProperties.ContainsKey("ecm_siterecordrestrictions"))
    {
        $Site.RootWeb.AllProperties["ecm_siterecordrestrictions"] = "BlockDelete"
    }

   if($Site.RootWeb.AllProperties.ContainsKey("ecm_siterecorddeclarationdefault"))
   {
       $Site.RootWeb.AllProperties["ecm_siterecorddeclarationdefault"] = "True"
   }

if($Site.RootWeb.AllProperties.ContainsKey("ecm_siterecordundeclarationby"))
{
    $Site.RootWeb.AllProperties["ecm_siterecordundeclarationby"] = "OnlyAdmins"
}

if($Site.RootWeb.AllProperties.ContainsKey("ecm_siterecorddeclarationby"))
{
    $Site.RootWeb.AllProperties["ecm_siterecorddeclarationby"] = "AllListContributors"
}

$Site.RootWeb.Update()
}

function Set-SharedDocumentSettings([Microsoft.SharePoint.SPWeb] $Web)
{
    $lib = $Web.Lists.TryGetList("Shared Documents")

if($lib -ne $null)
{
    $lib.EnableVersioning = $true
    $lib.EnableMinorVersions = $true
    $lib.EnableModeration = $false
    $lib.DraftVersionVisibility = "Reader"
    $lib.ForceCheckout = $true
    $lib.ContentTypesEnabled = $true

    $lib.Update()

    $lib.RootFolder.Properties["ecm_IPRListUseListSpecific"] = "True"
    $lib.RootFolder.Properties["ecm_AllowManualDeclaration"] = "True"
    $lib.RootFolder.Update()

    $documentCT = $lib.ContentTypes | Where-Object {$_.Name -eq "Document"}
    $lib.ContentTypes.Delete($documentCT.Id)

    $ct1 = $Web.AvailableContentTypes | Where-Object {$_.Name -eq "CTH-AU"}
    $ct2 = $Web.AvailableContentTypes | Where-Object {$_.Name -eq "CTH-BU"}

    $lib.ContentTypes.Add($ct1)
    $lib.ContentTypes.Add($ct2)

    $lib.Update()


}

}

function Set-AllDocLibSettings([Microsoft.SharePoint.SPWeb] $Web)
{
    foreach($lib in $web.Lists)
    {
        if($lib.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary)
        {
            $lib.EnableVersioning = $true
            $lib.EnableMinorVersions = $true
            $lib.EnableModeration = $false
            $lib.DraftVersionVisibility = "Reader"
            $lib.ForceCheckout = $true
            $lib.ContentTypesEnabled = $true

            $lib.Update()

            $lib.RootFolder.Properties["ecm_IPRListUseListSpecific"] = "True"
            $lib.RootFolder.Properties["ecm_AllowManualDeclaration"] = "True"
            $lib.RootFolder.Update()

            $documentCT = $lib.ContentTypes | Where-Object {$_.Name -eq "Document"}
            $lib.ContentTypes.Delete($documentCT.Id)

            $ct1 = $Web.AvailableContentTypes | Where-Object {$_.Name -eq "CTH-AU"}
            $ct2 = $Web.AvailableContentTypes | Where-Object {$_.Name -eq "CTH-BU"}

            $lib.ContentTypes.Add($ct1)
            $lib.ContentTypes.Add($ct2)

            $lib.Update()           
        }
}


}

$webApp = Get-SPWebApplication -Identity http://vmkulsp2:35384

foreach($Site in $webApp.Sites)
{
    #Common
    Set-Feature $Site
    Set-Audit $Site
    Set-ContentTypePublishingHub $Site
    Set-RecordDeclarationSetting $Site

$collaborateId = "112005"
$projectId = "112004"

foreach($web in $Site.AllWebs)
{
    $webTemplateId = $web.WebTemplateId.ToString()

    #Collobration Site
    if($webTemplateId -eq $collaborateId)
    {
        Set-SharedDocumentSettings $web
    }
    #project site
    elseif ($webTemplateId -eq $projectId)
    {
        Set-AllDocLibSettings $web
    }

    $web.Dispose()
}

$Site.Dispose()
}

Hope this helps the community Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.