Created
July 27, 2015 11:28
-
-
Save asadrefai/ffc9d7c8aaca756139a0 to your computer and use it in GitHub Desktop.
Create content organizer rule using csom PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
When I use this on Sharepoint online/365 the finding script doesn't find the rules I have set up using the GUI. If I run the script to create rules it will create one, but it doesn't show up in the content organizer rules list for the GUI. It seems like it is creating them in a different location than the rules in the GUI.
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
@benstegink No I haven't experienced this. But thanks for bringing this up, I will check if anything like that occurs.