Script Download: CheckSQLServerFragmentation.zip
http://gallery.technet.microsoft.com/scriptcenter/Check-SQL-Server-average-f96a1088

This script can be used to check your SQL Server average percent fragmentation and list the fragmentation between 5 and 30 or more than 30 percent.

By default, we can use New-OSCSqlConnection to create a SqlConnection and then use Get-OSCFragmentationInfo to get fragmented tables. Also, you can use Windows Authentication or SQL Server Authentication to connect your SQL Server. If you want to use SQL Server Authentication, just need to uncomment some code in this script.

 

image image
image

You can find more All-In-One Script Framework script samples at http://aka.ms/onescriptingallery