2 @PageCountLevel was replaced with @MinNumberOfPages by Hallengren last year.
source | link
EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @PageCountLevel =@MinNumberOfPages= 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';
EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_OFFLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @PageCountLevel@MinNumberOfPages = 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';
EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @PageCountLevel = 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';
EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_OFFLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @PageCountLevel = 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';
EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @MinNumberOfPages= 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';
EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_OFFLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @MinNumberOfPages = 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';
1
source | link

SqlWorldWide is right, but I'd take a step even further back and ask: Is defragmenting your indexes even helping anything?

There's a pretty big placebo effect for folks who rebuild indexes: they also update statistics. The updated stats give El Optimizero a better description of the data in your indexes, and may even chase a bad or inefficient query plan out of cache.

Most folks run Ola's script with the defaults. The problem there is that Microsoft published that guidance around the same time Windows Server 2003 was born. Computer hardware has come a long way since then. If your server still has a bunch of drives with rotating platters, it's time to start working on getting off that thing.

A more sensible way to run Ola's scripts, if you're on Enterprise Edition, is like this:

EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @PageCountLevel = 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';

If you're on Standard Edition, you can't Rebuild Online, so you could use this:

EXEC master.dbo.IndexOptimize @Databases = 'USER_DATABASES',
                              @FragmentationMedium = 'INDEX_REORGANIZE',
                              @FragmentationHigh = 'INDEX_REBUILD_OFFLINE,INDEX_REORGANIZE',
                              @FragmentationLevel1 = 50,
                              @FragmentationLevel2 = 80,
                              @PageCountLevel = 5000,
                              @UpdateStatistics = 'ALL',
                              @OnlyModifiedStatistics = 'Y',
                              @LogToTable = 'Y';

What do these buy you?

  1. Only working on indexes that have a fragmentation level that could start to show for larger scans
  2. Only working on indexes of a size where defragmenting them reduces the number of pages you'd have to read by a significant size
  3. Taking care of your modified statistics

If you start running maintenance with those settings, and no one fusses, you can switch from running them nightly to weekly. Or even monthly.

You're still going to want to update stats regularly though, and you can do that with this command:

EXECUTE dbo.IndexOptimize @Databases = 'USER_DATABASES',
                          @FragmentationLow = NULL,
                          @FragmentationMedium = NULL,
                          @FragmentationHigh = NULL,
                          @UpdateStatistics = 'ALL',
                          @OnlyModifiedStatistics = 'Y',
                          @StatisticsSample = NULL,
                          @LogToTable = 'Y';

Index maintenance is both annoying and confusing -- I used to be pretty stupid about it. Once I got over the OCD need to keep indexes as unfragmented as possible and started concentrating on things that actually helped performance, my servers were in much better shape. I also had a lot more time for important things, like DBCC CHECKDB.

Hope this helps!