none
unable to set retention policy for sharepoint content type using sharepoint poweshell + RRS feed

  • Question

  • Hello every one.

    I ma using sharepoint 2010, and management shell. i am trying to  set a retention policy(Declared) based on modified + 2 days , Policy set is working as expected but the documents under that content type is not Declaring.  below is the code.

    $policyxml = "<Schedules nextStageId='2'>"+
                "<Schedule type='Default'>"+
                    "<stages>"+
                        "<data stageId='1'>"+
                            "<formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'>"+
                                "<number>1</number>"+
                               #"<property>created</property>"+
                                "<property>ExpirationDate</property>"+
                                "<propertyId>28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f</propertyId>"+
                                "<period>months</period>"+
                            "</formula>"+
                            "<action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.Record' />"+
                        "</data>"+
                    "</stages>"+
                "</Schedule>"+
            "</Schedules>"
    $policyfeatureID = [Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration]

    $webapp = get-spwebapplication "Insight Portal"
    #********Moved this out of the loops since it only needs to be declared once
    $parentCtypes = @("Custom contenttype1","Custom contenttype2");


    $SiteStatus = Import-Csv -Path '.\input.csv' 

    foreach ($site in ($sitestatus | ?{$_.Status -ne "Success"})) 
    {
        $spsite = get-spsite $site.url
        # Get the SubSites/Webs in the Site Collection
        foreach($spWeb in $SPsite.AllWebs) 
        {
            Write-Host 'Web Site:' $spWeb.URL
           
            #Fill the array with base content types i.e. Exelon Content Page
    #********Instead of looping through all the content types, only grabbing the ones we want to update
            $ctypes = $spweb.contenttypes | ?{$parentCtypes -contains $_.name}
            foreach($ctype in $ctypes | ?{$_.name -ne $null})
            {
                Write-Host $ctype.Name -ForegroundColor Magenta
                $ctypePolicy = [Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::GetPolicy($ctype);
                if($ctypePolicy -ne $null)
                {
                    foreach($item in $ctypepolicy.Items)
                    {
                        $ctypePolicy.Items.Delete($item.id)
                        $ctypePolicy.Update();
                        $ctype.Update();
                    }
                }
                [Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::CreatePolicy($ctype, $null)
                $ctypePolicy = [Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::GetPolicy($ctype);
                $ctypePolicy.Items.Add($policyfeatureID,$policyxml);
                $ctypePolicy.Update();
                $ctype.Update();
                Write-Host "The Policy For" $ctype.Name "Has Been Created And Applied!" -ForegroundColor Green 
            }

                   $spweb.dispose()
        }
        $site.status = "Success"
        $SiteStatus | export-csv '.\input.csv' 
        $spsite.dispose()     



    Hari


    Friday, May 10, 2019 11:34 AM

Answers