0

I can't find the problem in my script to update my term store from items in the list "Companies" which are created since a year.

Function Process-Changes () {
$changeQuery = new-object Microsoft.SharePoint.SPChangeQuery($false, $false)
$changeQuery.Item = $true
$changeQuery.Add = $true
$changeQuery.Update = $true
$changeQuery.Delete = $true
$startTime = [DateTime]::UtcNow.AddDays(-100)
$changeQuery.ChangeTokenStart = new-object Microsoft.SharePoint.SPChangeToken([Microsoft.SharePoint.SPChangeCollection+CollectionScope]::List, $list.ID, $startTime)
$changes = $list.GetChanges($changeQuery)

#$changes = $list.Items

foreach ($change in $changes) {
    if ($global:verbose) {
        Write-Host "$($change.Id) - $($change.ChangeType) " -noNewLine
    }

    $modified = $false
    switch ($change.ChangeType) {
        'Delete' {
            $modified = Delete-Term $change.Id
        }
        'Add' {
            $modified = Add-Term $change.Id
        }
        'Update' {
            $modified = Update-Term $change.Id
        }
    }

    if ($modified) {
        $global:hasChanges = $true
        if ($global:verbose) { Write-Host " OK" -foregroundColor White }
    } else {
        if ($global:verbose) { Write-Host " NO CHANGES" -foregroundColor White }
    }
}

}

The error I get :

enter image description here

  • did you try with $startTime = [DateTime]::UtcNow.AddDays(-10) and execute the query.I suspect change log or Audit log might be not available for more than 90 days from current date in your case, may be i could be wrong. or if issue associated with this answer social.technet.microsoft.com/Forums/en-US/… – vinit kumar Dec 12 '18 at 13:51
  • Yes that's the problem.. I tried till 60 days and it work perfectly but i need to execute it for the items created since a year! and i cant change the changes log in the central admin! So any solution? – Jihen Dec 12 '18 at 13:54
  • Not sure about your requirement, but you have list called "Companies" and may be a column which is mapping with Termstore.You wanted to get change log so based on that you can update the Term store. I was saying why cant you go reverse way like first get the Terms available in Termstore and match in the List and update. if you find the term is not available in the List delete it.For New addition you might need to do again reverse read the List and add or update in Termstore. I am sure Change log for 1 year wont be available now and it would be deleted. – vinit kumar Dec 12 '18 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.