Create Record Center Content Organizer rules using Powershell

Create Record Center Content Organizer rules using Powershell

Here is how to Create a Record Center Sub Site , and add a Content Organizer rule to it.

First, We need to Create the Subsite.  The Template “OFFILE#1” is the Template for Record Center.  You can find all Sharepoint Templates here.

$mainURL = “http://vlad.test.loc”

$RecordCenterURL = “http://vlad.test.loc/RecordCenter“

$web = New-SPWeb $RecordCenterURL -Template “OFFILE#1”   -AddToTopNav

Now, here is the chunk of code to Create the Content Organizer Rule.

Write-Host -ForegroundColor White ” – Creating the Supporting Documents  Content Organizer Rule …” -NoNewline

 [Microsoft.SharePoint.SPSite]$site = Get-SPSite $mainurl

[Microsoft.SharePoint.SPWeb]$web = Get-SPWeb $RecordCenterURL

[Microsoft.SharePoint.SPContentType]$ct = $site.RootWeb.ContentTypes[“Document”]

[Microsoft.Office.RecordsManagement.RecordsRepository.EcmDocumentRouterRule]$rule = New-Object Microsoft.Office.RecordsManagement.RecordsRepository.EcmDocumentRouterRule($web)

$rule.ConditionsString = “

$rule.CustomRouter = “”

$rule.Name = “Supporting Documents Rule”

$rule.Description = “Routes ‘” + $ct.Name + “‘ documents to the records library”

$rule.ContentTypeString = $ct.Name

$rule.RouteToExternalLocation = $false

$rule.Priority = “5”

$rule.TargetPath = “/Records/Records”

$rule.Enabled = $true

$rule.Update()

Write-Host -ForegroundColor GREEN “Done.”

Write-Host

As you can see, this rule routes the Content Type “Document” to the /Records/Records Library. 

No ratings yet.

Please rate this

 
Comments

I am using a variation on this script posted here my script pulls from a CSV file because I have over 600 rules to add. The script works and the rules work, however as I add more and more rules the time to create them increased, from 10-15 seconds to 5mins 10secs.

Ive tried IISRESET, rebooting servers thinking its a build up of cache but its taking 5 minutes 10 seconds to run the 7minutes and it seems to get worse as I add more. If there an underlining issue im not seeing?. at this rate it will take another 48+hours to create the rules I need.

This is sometimes an issue with all the PowerShell scripts. Try splitting them into maybe 10 files of 60 “rules”. Let me know if it worked!

Thanks for the reply, I did end up splitting them into batches of 60-70 but it would get progressively worse, At its peak it took 30 minutes per rule then when it reached the last two rules it took seconds….weird behaviour. I did notice some ULS logs complaining about Slow SQL Queries, but I’ve never been able to find more details in SQL.

Leave a Reply