SQL Monitor 9

Your first script

Develop your first PowerShell script from the scratch.

If you have any questions, suggestions or feedback please let us know.


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) Create an empty PowerShell file (e.g "example.ps1") in the same directory where you downloaded the PowerShell Module. Open it using a text editor.

4) Import the downloaded PowerShell module:

using module .\RedgateSQM.psm1

5) Next, you will need to initialize the PowerShell Module with the authentication token you generated in step 1:

Initialize -AuthToken "GeneratedAuthenticationToken"

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

$clusters = Get-Clusters
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 your PowerShell script:

.\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?