SQL Monitor 13

Your first script

Develop your first PowerShell script from scratch.

Listing all clusters monitored by SQL Monitor

1) Generate an authentication token. See the Authentication page for details.

2) Download the PowerShell Module. See Downloading the PowerShell Module page for details.

3) Extract the downloaded .zip file. Create an empty PowerShell file (e.g. "example.ps1") in the same directory where you extracted the PowerShell Module. Open it using a text editor.

4) Import the PowerShell module:

Import-Module .\RedgateSQM

5) Next, you will need to connect SQL Monitor with the authentication token (generated in Step 1) and the URL of the SQL Monitor:

Connect-SqlMonitor -ServerUrl 'http://mysqlmonitorserver:8080' -AuthToken 'GeneratedAuthenticationToken'

6) Fetch all clusters and print them to the console:

$servers = Get-SqlMonitorMonitoredObject
foreach ($server in $servers)
{       
    Write-Output $server.Name
}

7) Save the file, open a new terminal in the same directory of your script, then execute it:

.\example.ps1

8) You will see the machines that are monitored by SQL Monitor:


Do you have any feedback on this documentation?

Let us know at sqlmonitorfeedback@red-gate.com


Didn't find what you were looking for?