In order to fix it go to Central Administration > Service applications > Search service application > Metadata properties > Edit "Content type" property (or property which you use) > Check checkbox "Allow this property to be used in scopes":

After this New-SPEnterpriseSearchQueryScopeRule cmdlet should work successfully.

In one of the projects when I tried to execute similiar script I encountered with the following error when call CommitAll() method:

Failed to read from or write to database. Refresh and try again. If the problem persists, please contact the administrator.

Sharepoint log had more details including stack trace and internal exception:

Exception returned from back end service. System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: TermStoreEx:Failed to read from or write to database. Refresh and try again. If the problem persists, please contact the administrator. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: Microsoft.SharePoint.Taxonomy.TermStoreOperationException: TermStoreEx:Failed to read from or write to database. Refresh and try again. If the problem persists, please contact the administrator. ----> System.Data.SqlClient.SqlException: Cannot insert duplicate key row in object 'dbo.ECMTerm' with unique index 'IX_ECMTerm_TermGUID'. The duplicate key value is (7acd1222-a19a-4c46-866e-f840c3f0a48b, 8272295a-288e-4aac-9da6-ad733c6ecc66). The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReade...).

As it shows the exact error is that there already was term with the same id in the managed metadata table (Cannot insert duplicate key row in object 'dbo.ECMTerm' with unique index 'IX_ECMTerm_TermGUID'). I checked whole solution for occurrence of specified id and found that it was used already in another feature which provisions term sets. So I changed id in the PowerShell and after that it became working. Hope it will help you if you will encounter with the same issue.

About Me

I've created this blog for sharing my technical experience in software engineering. Most of posts will be dedicated to Sharepoint. But I will write also about another areas of software development for .Net platform. Hope it will be useful and will help you in your work.