I’ve been developing for DBATools for a while now and while its great to help on tool that looks to have been widely excepted and picked up by the community. it’s also been an amazing learning opportunity for me as well (mainly thanks to ever ready Chrissy LeMaire original creator of DBATools).

A recent addition and one I think is a hidden gem that more people should play around with and promote is Connect-DbaSqlServer. This is the same code that all the DBATools team use to create there SMO connections, while it used to be hidden in the internal functions (making it unusable for module users) they have created a copy of the function for everyone to use, this means if you are thinking of writing a PowerShell query that connects to SQL Server, you no longer have to worry about all the connection settings, changing your credentials (if you want to/need to) loading in the SMO object.. etc etc Its done and dusted and you can get to work on the problem your trying to solve…

For me this is a really awesome and I have no idea why its taken this long to do, or why i didn’t think to ask why it wasn’t available for so long..

I wont give some examples of how to use it, instead i will say, think of what data you need to gather and take a look on the DBATools GitHub, there is bound to be something vaguely in the ball park (If there isn’t and you want us to make it. jump on Trello or Slack to let us know).  Rip out all the junk you dont need or that doesn’t make sense. and get started. Because the below line in my mind is epic and give you endless fun and adventure…

$server = Connect-DbaSqlServer -SqlServer "MySQLBox"

You want all your databases..

$server.Databases

You want to look at your agent jobs.

$server.JobServer.jobs

You want logins

$server.Logins

You know you want to do something credentials but dont know where it is

$server | gm -name *cred*

Its so easy to start exploring.. I really hope this gets people trying to write there own code and start playing.. because as soon as you get passed that first hurdle of connecting to the server, you can start spamming the Get-Member command to work your away around and get what you need..

Advertisements