Adding New Targets with the SQL Sentry and DBATools Powershell module |
|
You finally got approval for SQL Sentry, it’s purchased and installed. Now I have the lovely task of manually adding all the targets to be monitored. If you are in a medium to large shop, this can be hundreds to thousands of servers. That sounds like a job for a junior DBA or… we can leverage the SQL Sentry Powershell module to make quick work of this.
SQL Sentry Powershell documentation
In my code example, I have a Server Inventory table. I am using Invoke-DBAQuery from the DBATools module to populate the variable to loop through, register the computer add then new SQL Server instance to be watched. If you do not have a Server Inventory table but have a Central Management Server you could use this DBATools Cmdlet instead Get-DbaRegServer. I will also mention using a CSV file in an example later in this post. Quick note, if you are not using DBATools, you should, it makes the life of a DBA so much easier .
DBATools Documentation
This is not a “super-fancy” script, but if you want to add more functionality this gives you the framework to take it in any direction you want.
I have not included all of the script in this screen shot but you can download the file at the bottom of this post.
SQL Sentry Powershell documentation
In my code example, I have a Server Inventory table. I am using Invoke-DBAQuery from the DBATools module to populate the variable to loop through, register the computer add then new SQL Server instance to be watched. If you do not have a Server Inventory table but have a Central Management Server you could use this DBATools Cmdlet instead Get-DbaRegServer. I will also mention using a CSV file in an example later in this post. Quick note, if you are not using DBATools, you should, it makes the life of a DBA so much easier .
DBATools Documentation
This is not a “super-fancy” script, but if you want to add more functionality this gives you the framework to take it in any direction you want.
I have not included all of the script in this screen shot but you can download the file at the bottom of this post.
I also wanted to provide an example from one our customers, Adrian Mioduszewski, and how he is using this type of functionality. His script is more robust than my example and uses more cmdlets from the SQL Sentry module to check if the server being added is already a target in SQL Sentry. Also in Adrian’s example, he is using a CSV file as the list of servers to be added.
I hope these examples will help you get up and running with SQL Sentry quickly and efficiently.
addnewtargets.ps1 | |
File Size: | 4 kb |
File Type: | ps1 |