All posts filed under: SQL

PoshUtils: Get all mirrored SQL databases using PowerShell and SMO

I have been validating different aspects of SQL mirroring and in the process I wanted a quick and automated way to handle database mirroring functions. This includes listing all mirrored databases, failing over databases manually to a mirrored instance, etc. So, in the process, I created several small functions in PowerShell to achieve what I wanted. I will share these functions as a series of posts and eventually, will release a PoshUtils module. So, in today’s post, let us see how we can retrieve a list of all SQL databases that are mirrored. This function can work with both default and named instances. Also, this assumes that you are using Windows authentication. Let us see the function:

When you run the Get-MirroredDatabase function, it returns a list of all databases that are mirrored and all properties of each database. You can filter the output by selecting the properties you want.

Creating SQL snapshots using SMO and PowerShell

First of all, I am not SQL guy. I work on SharePoint quite a bit and venturing into SQL now. So, the first thing is to learn how I can script my SQL management tasks. I know there are quite a few things on the Internet but exploring all this myself gives an opportunity to learn how SQL works. This post is about how we can use SQL Management Objects and PowerShell to create database snapshots. Make a note, I did not mention T-SQL. I am not sure if someone else already a wrote post around this or not. But, this is just the way I learned to do it. Do let me know if you know a better way or done it earlier. With no further delay, here is the script.

I have enough inline comments in the above code to explain what it is doing. Remember, you need SQL Enterprise edition to use DB snapshots. This is it. I am off to exploring how I can revert a snapshot without using T-SQL …