1

I am working on PowerShell to create term in SharePoint Online and before I create one I am trying to see if it already exists. In order to see that I am using below "GetByName" function.

$objSearchTerm = $objTermSetName.Terms.GetByName($termName)
$clientContext.Load($objSearchTerm)
$clientContext.ExecuteQuery()

This works if there is a term with the name but throws an exception if the term does not exist.

Exception calling "ExecuteQuery" with "0" argument(s): "Specified argument was out of the range of valid values. Parameter name: index"

I can not use PnP because I am creating child term with custom properties so please do not suggest PnP solution because PnP doesn't support that.

0

You can use Try..Catch block to catch the exception if it does not exist. I guess you are trying to catch the error so that it does not stop the execution when there is no term.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.