I'm writing a powershell script that creates folders in a Records Library using SharePoint document routing rules, and am able to set the conditions, name, description etc. Where I'm having difficulty is explicitly setting the Target Location field so that the folder is automatically created for the unique value of a property of the document. Essentially, I want to be able to set what I have below as part of my powershell script. Anybody have any tips that could lead me in the right direction?
Here is the code I have tried so far:
#store the config & global variables
$ctConfig = [xml](Get-Content $configXMLPath);
$RecordCenterURL = "http://spvm/sites/assessrc"
$web = Get-SPWeb $RecordCenterURL
$docLib = $web.Lists["Record Library"]
$conField = $docLib.Fields.GetField("Confidential Document")
$ppmField = $docLib.Fields.GetField("PPM ID")
foreach($xmlContentType in $ctConfig.ContentTypes.ContentType)
{
#Write-Host "Creating rules for" $xmlProdFam.Name "..."
#Create Rule
[Microsoft.SharePoint.SPSite]$site = Get-SPSite $RecordCenterURL
[Microsoft.SharePoint.SPWeb]$web = Get-SPWeb $RecordCenterURL
[Microsoft.SharePoint.SPContentType]$ct = $site.RootWeb.ContentTypes[$xmlContentType]
[Microsoft.Office.RecordsManagement.RecordsRepository.EcmDocumentRouterRule]$rule = New-Object Microsoft.Office.RecordsManagement.RecordsRepository.EcmDocumentRouterRule($web)
$rule.ConditionsString = "<Conditions><Condition Column='" + $conField.Id + "|ConfDoc|Confidential Document' Operator='IsEqual' Value='False'></Condition></Conditions>"
$rule.CustomRouter = ""
$rule.Name = "Non-Confidential " + $ct.Name + "Routing Rule"
$rule.Description = "Routes '" + $ct.Name + "' documents from the '" + $xmlProdFam.Name + "' Product Family to the records library"
$rule.ContentTypeString = $xmlContentType.Name
$rule.RouteToExternalLocation = $false
$rule.Priority = "5"
$rule.TargetPath = $site.SubFolders["PPM ID"];
$rule.enabled = $true
$rule.Update()
}
