Thanks for taking the time to share this with us. Great script. I did however find one issue that was easily fixed though. The same index name can exist in multiple tables. I thought I was getting duplicates until I looked at the CREATE INDEX DDL column and found that the code returned for 1 table was for creating the index on 2 DIFFERENT tables. The statement that needed to be fixed was:
FROM #TMP2 a INNER JOIN #TMP1 b ON a.indexname = b.indexname
Which I changed to:
FROM #TMP2 a INNER JOIN #TMP1 b ON a.indexname = b.indexname AND a.ObjectName=b.TableName
That fixed my problem. Thanks again.
Lee