To print commands ALTER INDEX ... REORGANIZE or REBUILD for the indices of database TestDB with avg_fragmentation_in_percent greater than 10 (%) is sufficient run:
EXEC USP_ExecReorgRebuildIndex 'TestDB', 0, -1, 10
To run the defragmenter, use instead:
EXEC USP_ExecReorgRebuildIndex 'TestDB', -1, 0, 10