SchemaXML vs CSOM - update

Hello,

I faced problem with change SchemaXML of ManageMetadata (taxonomy) field using CSOM. During run I not receive any errors so investigation is very hard...

Because of Manage Metadata Service structure change I need to update SSPID ( so term store ID) inside each taxonomy fields from old SSP ID =>$regex = 'b31429cc-688c-4393-bcb7-b60cf631ca42'  to new SSP ID =>   [string]$abc = "13e722c5-bebe-4801-a6ac-67aa35eba088"

SCRIPT:

$16Hive = "C:\DLLs"

Add-Type -Path "$16Hive\Microsoft.SharePoint.Client.dll" Add-Type -Path "$16Hive\Microsoft.SharePoint.Client.Runtime.dll"   $url = "https://contoso.sharepoint.com/sites/somesite" $User = "myaccount@contoso.onmicrosoft.com" $Password = Read-host -Prompt "Please enter your password" -AsSecureString $officeClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url) $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password) $officeClientContext.Credentials = $Creds return $officeClientContext   $logger = new-object System.Text.StringBuilder function Log($message) {                 Write-Host $message                 [void]$logger.AppendLine($message) }   $web = $officeClientContext.Web $officeClientContext.Load($web) $fields = $web.Fields $officeClientContext.Load($fields) $officeClientContext.ExecuteQuery() $corruptedFields = $fields | ? { $_.TypeDisplayName -like "*Managed Metadata*" }   Log $("Fix SiteColumns for site: " + $officeClientContext.Url) foreach($field in $corruptedFields) {                 if ($field.SchemaXml.Contains('SspId')) {                                $regex = 'b31429cc-688c-4393-bcb7-b60cf631ca42'                                if ($($field.SchemaXml -match $regex)) {                                                $matchedValue = $matches.Values                                                Log $("Change schema " + $matchedValue)                                                [string]$abc = "13e722c5-bebe-4801-a6ac-67aa35eba088"                                                $field.SchemaXml = $field.SchemaXml.Replace($matchedValue, $abc)             
                                                 }                 }                   $field.Update()                 $officeClientContext.ExecuteQuery() }  

return $logger.ToString()

Thanks for help.

September 8th, 2015 8:24am

Hi Michal,

The following script for your reference:

$16Hive = "C:\DLLs"

Add-Type -Path "$16Hive\Microsoft.SharePoint.Client.dll"
Add-Type -Path "$16Hive\Microsoft.SharePoint.Client.Runtime.dll"

$url = "https://***.sharepoint.com/sites/dennis"
$User = "dennis@***.onmicrosoft.com"
$Password = Read-host -Prompt "***" -AsSecureString

$officeClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$officeClientContext.Credentials = $Creds
$web = $officeClientContext.Web
$field = $web.Fields.GetByTitle("Field Name")

$officeClientContext.Load($field)
$officeClientContext.ExecuteQuery()

$field.SchemaXml = $field.SchemaXml.Replace('b31429cc-688c-4393-bcb7-b60cf631ca42', "13e722c5-bebe-4801-a6ac-67aa35eba088");
$field.Update();

$officeClientContext.ExecuteQuery()

Best Regards,

Dennis Guo

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 1:12am

Hi,

Thanks for help but your script doesn't work. Please after run open a new powershell window , then  try to check the field --> you will see still old value.

September 9th, 2015 3:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics