(This post comes from one of our Junior DBAs – @SQLDork)
I’ve been learning dbatools over the past week or so, you can read the previous blog posts here and here.
You can read the current one here, or just scroll down i guess.
Today’s Command: Get-DbaLastBackup
Get-DbaLastBackup `
-SqlInstance PRECISION-M7520SQL2016Nothing fancy, just spits out the last backup info for each database on the box.

Get-DbaLastBackup `
-SqlInstance PRECISION-M7520SQL2016 | `
Select-Object *This gives us some more useful information, telling us the number of days since the database was created/backed up, the backup type, etc.

Get-DbaLastBackup `
-SqlInstance PRECISION-M7520SQL2016 `
-Database testSpecify which database you want to check, defaults to all of them.
Get-DbaLastBackup `
-SqlInstance PRECISION-M7520SQL2016 `
-ExcludeDatabase testSpecify that you don’t want to check a certain database. Again, not using this or -Database will return data on all of them.
Get-DbaLastBackup `
-SqlInstance PRECISION-M7520SQL2016 | `
Select-Object * | `
Out-GridviewFormatting, puts the data in a grid. Useful for pasting into excel or something. Though there’s no way to copy the headers as far as i can tell, so you’ll have to put those in manually.
(Click image to enlarge in new tab)
Get-DbaLastBackup `
-SqlInstance PRECISION-M7520SQL2016 | `
Select-Object Database,RecoveryModel | `
Out-GridviewOnly select some columns, rather than all of them.

Get-DbaLastBackup `
-SqlInstance PRECISION-M7520SQL2016 | `
Select-Object * | `
Export-Csv `
-Path C:output.csv `
-NoTypeInformationHow about we pipe the output to excel/CSV directly instead of pasting it in? Sounds like a good idea to me!
(Click image to enlarge in new tab)
That’s all i (b|t) have for today, but it wouldn’t be a SQLDork blog post without several links to my twitter at the end!
The post TIL: Get-DbaLastBackup appeared first on DallasDBAs.com.


