powershell

Lesson Learned From Multi-Threading with dbatools

Andy Levy

Over the summer, I spent some (a lot of) time working on updates to a script at work which runs multiple processes in parallel. Everything seemed to work OK for a while, but then everything broke. It broke right around the time dbatools 1.1 dropped, so I started thinking that something must have changed there. As it turns out, it was entirely my fault and I hope this post will help you avoid the same trap.

Slides & Demos for Backup Basics with PowerShell & dbatools

Andy Levy
I had the honor of presenting a new session, Backup Basics with Powershell and dbatools, at the first Ohio North Database Training meeting this evening. Thank you to the group leaders for the opportunity and to everyone who attended. Because this was both a brand new session and an attempt at a new way of delivering the presentation, I had a couple tech glitches but things went pretty well once they were understood and ironed out.

Restoring Database Users After Copying the Database

Andy Levy
A former colleague emailed me with a question about retaining/fixing database users and permissions after restoring a database. They were copying a database from one instance to another, with different logins, users, and permissions between the two instances. Backup & restore to copy the database is easy enough, but because users & permissions are kept inside the database itself, the destination environment loses all its permissions settings in the process. What to do?

Shell to Script Shortcut

Andy Levy
I’ve been meaning to write something this post for a while but the stars have aligned this week. Garry Bargsley (blog | twitter) published a post about making a schema-only copy of a database on the day that I needed to solve that exact problem. But that’s not what this is about. It’s just a convenient way to demonstrate this shortcut. I’m sure that a lot of folks do work on the PowerShell command line, trying various things, before committing to writing a full script or function.

Finding & Downloading Required SQL Server Updates

Andy Levy
A little while back, I offered up a one-liner to scan your SQL Server instances and report which ones are out of date. But what if you need to take the next step, determining which updates need to be downloaded? That’s exactly what Josh asked on the SQL Community Slack recently. Can Test-DbaBuild also bring back the KB number? From reading the docs it looks possible as it does return the compliant version form the .

Checking for SQL Server Updates with dbatools

Andy Levy
It turns out I was doing this all wrong for months. For the longest time, I’ve been checking my SQL Server instances to see what needs patching with Test-DbaBuild from the dbatools PowerShell module. But the result was always the same - it never returned a Service Pack or Cumulative Update target. I glossed over it because I knew what the right answer was already, but recently I decided that wasn’t good enough.

Does dbatools Have a Function for That?

Andy Levy
dbatools has a lot of functions. A lot. Over 550. There is a great command index on the website, and the documentation gets updated every time a new version is published. But sometimes, it feels like you can’t find what you need unless you already know the name of the thing you’re looking for. Other times, you might start writing your own wrapper around dbatools functions, or maybe start a new function from scratch, because it seems like the functionality you need isn’t there.

Monday Morning Module Maintenance Monoliners

Andy Levy
Or: Andy Authors An Amazing Alliteration Do enough work with PowerShell and you’ll build up a decent collection of modules installed from the gallery into either your computer or your user profile (or maybe both!). Here are two one-liners to help keep things up to date and tidy. Note: I’m calling these one-liners but I’ve inserted line breaks for readability here. These do count as one-liners as each one is a single, unbroken PowerShell pipeline.