I’ve been playing around Chad Miller’s SQL Server PowerShell Extensions – SQLPSX 1.5 on CodePlex getting ready for my TechEd session Manageability Series: Microsoft SQL Server Automation on Steroids, Including Powershell on Wed 5/13.
Chad has developed huge library of Powershell cmdlets, functions, and scripts that hit the key scenarios for SQL Server DBAs. All of the functions that Chad developed can be accomplished using the SMO object model calls, but Chad’s functions exposes them like you would expect to see them in PowerShell.
For example, once you install his library along with using either the SQL PowerShell shell or a PowerShell 1.0 shell referencing the SQL snapins – see Running SQL Server PowerShell – you can mix and match functionality.
For example, take his example of running DBCC CheckDB for a database.
#Get a database object and set to a variable
$db = get-sqldatabase ‘SQL1\DEMO1’ pubs
#Run a checkdatabse
That’s all it takes – no need to use the SMO object model. You can use a command like this to run DBCC CheckDB against all databases:
dir | invoke-sqldatabasecheck