Skip to content

Instantly share code, notes, and snippets.

@asadrefai
Created July 27, 2015 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asadrefai/ffc9d7c8aaca756139a0 to your computer and use it in GitHub Desktop.
Save asadrefai/ffc9d7c8aaca756139a0 to your computer and use it in GitHub Desktop.
Create content organizer rule using csom PowerShell
# replace these details (also consider using Get-Credential to enter password securely as script runs)..
$username = "SomeOne@SharePoint.onmicrosoft.com"
$password = "YourPassword"
$url = "https://YourSite.sharepoint.com"
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
# the path here may need to change if you used e.g. C:\Lib..
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
# connect/authenticate to SharePoint Online and get ClientContext object..
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$clientContext.Credentials = $credentials
if (!$clientContext.ServerObjectIsNull.Value)
{
Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
$web = $clientContext.Site.RootWeb
$listRoutingRules = $web.Lists.GetByTitle("Content Organizer Rules")#RoutingRules
$clientContext.Load($listRoutingRules)
$clientContext.ExecuteQuery()
#Add an item to the list
$ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$Item1 = $listRoutingRules.AddItem($ListItemInfo)
$Item1["Title"] = "Asad Test Rule"
$Item1["RoutingRuleName"] = "Asad Test Rule"
$Item1["RoutingRuleDescription"] = "Asad Test Rule"
$Item1["RoutingPriority"] = 1
$Item1["RoutingEnabled"] = $true
$Item1["RoutingContentType"] = "Your Content Type Name"
$Item1["RoutingContentTypeInternal"] = "0x000000000000000000000000000000000000000000000000000000|Your Content Type Name"
$Item1["RoutingConditions"] = '<Conditions><Condition Column="xxxx-xxx-xxx-xxx-xxxxxx|ColumnName|Column Name" Operator="EqualsOrIsAChildOf" Value="1;#Value|xxxx-xxx-xxx-xxx-xxxxxx" /></Conditions>'
$Item1["RoutingConditionProperties"] = "Condition Property"
$Item1["RoutingAliases"] = "Alias Name"
$Item1["RoutingTargetLibrary"] = "Target Library"
$Item1["RoutingTargetFolder"] = ""
$Item1["RoutingTargetPath"] = "/sites/YourSite/Target Library"
$Item1["RoutingAutoFolderProp"] = "Folder Property"
$Item1["RoutingAutoFolderSettings"] = '<AutoFolder><Properties><Property Name="AutoFolderEnabled" Value="True" /><Property Name="AutoFolderPropertyName" Value="Your Value" /><Property Name="AutoFolderPropertyInternalName" Value="YourValue" /><Property Name="AutoFolderPropertyID" Value="xxxx-xxx-xxx-xx-xxxxx" /><Property Name="AutoFolderPropertyFormat" Value="%1 - %2" /><Property Name="AutoFolderPropertyTypeAsString" Value="TaxonomyFieldType" /><Property Name="AutoFolderPropertyTermStore" Value="xxxx-xxx-xxx-xxx-xxxxxx" /></Properties></AutoFolder>'
$Item1["RoutingCustomRouter"] = ""
$Item1["RoutingRuleExternal"] = $false
$Item1.Update()
$clientContext.ExecuteQuery()
Write-Host "Rule created successfully" -ForegroundColor Green
}
@JeanNetryValere
Copy link

JeanNetryValere commented Dec 4, 2017

Same behavior than @benstegink even if completing the provisioning by setting the linked property bags. Is there any additional task to achieve to get it work ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment