PowerShell Provider for SQL Server Script of the Day – Script all objects


If you’re using the PowerShell provider for SQL Server, you can quickly script out all of the objects in a "directory" using a simple method. Just navigate to the directory of objects you’re interested in, say the "Views" of a certain database, and type this:

# Script objects in a directory
DIR * | foreach {$_.Script()}

This will only work for objects that can be scripted, of course, and requires that you have the proper permissions.