SQL Monitor 10

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:

using 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 machines and print them to the console:

$clusters = Get-SqlMonitorCluster
foreach ($cluster in $clusters)
{       
    Write-Output $cluster.Name
}

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

.\example.ps1

If you see an error indicating that the script is not digitally signed, you may need to allow unsigned scripts to be executed. You can apply this to a single PowerShell session with the following command:

 Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted

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?