Automating: Configuring Settings
Once that variable is populated, we can use PowerShell’s remoting capabilities to set the settings on the target systems in parallel using the Invoke-Command cmdlet. By default, Invoke-Command
will execute the task on up to 32 simultaneous servers, but you can use the -ThrottleLimit parameter to set your own preferred maximum. If you exceed the maximum, Invoke-Command
will continue with the remaining servers as the initial ones are complete. Needless to say, executing these tasks in parallel across your target servers is far faster and more efficient than iterating through them one at a time.
To set the network firewall settings on all servers, I execute this command.
The last command adds the TESTDOMAIN\s1svc account in my domain to the local administrators group on each target server. It uses the COMPUTERNAME environment variable to select the local group, and the USERDOMAIN environment variable to specify the domain name.
Automating: Power Settings
The next command I run doesn’t need to be run for the SentryOne process, but it is a best practice in SQL Server environments, as it sets the Power setting of each server to High Performance. Many servers are left at the Balanced setting, which can negatively impact performance.
It works by getting the list of power plans on the target system, filtering for the one named ‘High Performance’, and then activating that plan using Invoke-CimMethod.
Automating: SentryOne Service Account
The next steps involve executing the Transact-SQL code to add the domain SentryOne service account as a Windows Login on each target SQL Server instance, and adding it to the sysadmin server role on each instance. Because I’m running this from the monitoring service server, where I haven’t installed any SQL Server tools, I’m using ADO.NET, which doesn’t require any external modules. It’s always there when you’re running PowerShell.
The SqlConnection
object needs a standard connection string, and I use the COMPUTERNAME environment variable to specify the local server in the string. I open the connection, then build the CREATE LOGIN query in $q. The SqlConnection
object and the query are the only parameters needed for the SqlCommand
object, which has the method ExecuteNonQuery()
, which adds the login. I then use the same steps to add the login to the sysadmin server role and close the connection.
SentryOne Setup
Now that the requirements are in place in all targets, I can manually execute the SentryOne setup program, where I specify Do Not Install for everything but the Monitoring Service. I specify WS16SQL2 as the target for the SentryOne repository database and verify that my login can access that server. On the next dialog I specify the SentryOne service account (TESTDOMAIN\s1svc) and complete the installation. Now the monitoring service is running on WS16MS0, and I can now continue.
Since the monitoring service has been installed, I can now import the SentryOne PowerShell module, and connect to the repository on WS16SQL2.
License Key
To save time during the client installation later, I can use ADO.NET again to load the license key into the repository database. The license key is XML, and goes into the LicenseText column in the dbo.License table, so I get the XML out of the file using Get-Content, and use the same ExecuteNonQuery()
to execute the insert statement in the repository database.
Register Targets
Once that’s done, I’ll iterate through the servers in servers.txt to register each target in the repository. The USERDNSDOMAIN environment variable contains the full domain name (TESTDOMAIN.COM in this case), so for server WS16SQL1 the -Name argument receives WS16SQL1.TESTDOMAIN.COM, the fully qualified domain name of the server.
Client Installation
At this point, I switch to the workstation where I’ll install the client. I only need to copy the SentryOne install program there and run it. I opt to install every component except the monitoring service, specify WS16SQL2 as the server hosting the SentryOne repository database, and when it’s done, indicate that I want to run the S1 client. When it opens, it displays my name and email address (which it got from the license key I’ve already inserted into the dbo.License table), which I verify.
When it opens to the navigator, I close the client, and open up a PowerShell window on the client. After loading the SentryOne PowerShell module, I connect to the repository, as I did on the other system, but now I can use the Get-Connection
cmdlet, and pipe the result to the Invoke-WatchConnection
connection, which starts the monitoring service watching each of the targets registered earlier.
Setup Complete!
At this point the installation and setup steps are complete. SentryOne is collecting data to allow you to be more effective at solving performance issues across your entire environment. Whether you have 10 or 1000 servers to monitor, the SentryOne PowerShell module will get you monitoring them quickly.