Welcome to Day 11 of my “A Month of PowerShell” series. This series will use the series landing page on this blog at http://blog.waynesheffield.com/wayne/a-month-of-powershell/. Please refer to this page to see all of the posts in this series, and to quickly go to them.

Yesterday we took a look at the SMO object model diagram and dug down into servers and databases. Today, let’s play around with databases a bit more.

Adding Databases

Yesterday we looked at some of the database properties that are available. So what’s left to do with databases? Today, let’s add one so that we can play around with it in future episodes of this series. (The basis of this script is from Allen White as he blogged at http://sqlblog.com/blogs/allen_white/archive/2008/04/28/create-database-from-powershell.aspx.)

[codesyntax lang=”powershell” strict=”yes”]

[/codesyntax]

Alter database using SMO class objects

[codesyntax lang=”powershell” strict=”yes”]

[/codesyntax]

Alter database using SQLSERVER PSDrive

The above can also be performed using the PSDrive SQLSERVER:

[codesyntax lang=”powershell” strict=”yes”]

[/codesyntax]

Drop database

If you wanted to drop the database:

[codesyntax lang=”powershell” strict=”yes”]

[/codesyntax]