dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Displays information relating to SQL Server Optimize for AdHoc Workloads setting. Works on SQL Server 2008-2016.

When this option is set, plan cache size is further reduced for single-use adhoc OLTP workload.

These are just general recommendations for SQL Server and are a good starting point for setting the “optimize for adhoc workloads” option. Check out Glenn Berry’s SQL Server Performance for more information.



Get Optimize for AdHoc Workloads setting for servers sql2008 and sqlserver2012 and also the recommended one.

Test-DbaOptimizeForAdHoc -SqlServer sql2008, sqlserver2012



This command was created by Brandon Abshire. You can find Brandon blogging at netnerds.net.


From PowerShell, execute Get-Help Test-DbaOptimizeForAdHoc -Detailed for more information on this function.

Source Code

Want to see the source code? View Test-DbaOptimizeForAdHoc.ps1 on GitHub

Related commands