With PowerShell and SQL Server Management Objects (SMO), you can create powerful scripts to document and manage your SQL Server instances. Introduced in SQL Server 2005 as part of the SQL Server Features Pack, SMO is designed for managing SQL Server through programming.
Since the introduction of PowerShell, it's possible to consume the SMO namespace and produce some amazing scripts using PowerShell.