Open for Voting

Add ability to change Node Details Poller from the SDK/Powershell

Whilst I understand I can update the node details poller on the manage pollers page, its limited to manually selecting groups of devices. I'd find it really handy to be able to script this using powershell, e.g. when adding new devices via script. I already set custom properties, other pollers automatically and the node details poller is the only one thats missing.

See below for a pic of the node details poller item that I am referring to.

This has been discussed @ - see here for more info.



Parents Comment Children
  • Hi ,

    Sure can, sorry for the delay.

    I'm using the PowerShell module 'SqlServer' which is available on the PowerShell Gallery. I have some examples for both PowerShell and Python on my Github repo:

    Here's an example read query to provide familiarity:

    Import-Module SqlServer
    $ServerInstance = "SQLSERVERNAME\INSTANCE"
    $Database = "SolarWindsOrion"
    <#	The below string is the SQL query.
    	My databases include the ".[dbo]" between the database name and table, sometimes that's not the case.
    	I chose to insert the database name into the FROM statement via the existing database name variable from above.
    	This is just selecting the top 3 records of nodes, with only the Caption value.
    $Query = @"
    SELECT TOP 3 Caption
    FROM [{0}].[dbo].[NodesData]
    "@ -f $Database
    <#	Here we invoke the SQL Query.
    	This version is using the Active Directory account (I assume Kerberos token) of the user runing the PowerShell instance.
    	If you need to use a SQL account instead, choose the Username + Password or Credential parameters. Unfortunately those
    	parameters cannot be used with Active Directory based accounts due to limitations of the PowerShell module. If you need
    	to run the command with a different Active Directory user you will need to either: execute PowerShell with that account,
    	or if trying to use "Invoke-Command" to execute this step under a different set of credentials you will need to have
    	"CredSSP" enabled on the machine running the script. As I understand it using CredSSP is not recommended for security
    Invoke-Sqlcmd -ServerInstance $ServerInstance -Database $Database -Query $Query 

    To actually assign a DeviceStudio type poller to a node, use this query:

    UPDATE [{0}].[dbo].[DeviceStudio_PollerAssignments]
    SET [Enabled] = 1
    WHERE [ID] IN (
      FROM [{0}].[dbo].[DeviceStudio_PollerAssignments] PA
      INNER JOIN [{0}].[dbo].[DeviceStudio_Pollers] P
      ON PA.PollerID = P.PollerID
      WHERE P.Name = '{1}' AND PA.NetObjectType = 'N' AND PA.NetObjectID = {2}
      0 = databse name
      1 = DeviceStudio poller name
      2 = NodeID

    I used the -f string method of inserting those variables into this query in the same manner as the above example.

    Hope this helps! Slight smile

  • This is fantastic, thanks Martin.
    I've integrated it into my script and its working perfectly.

    Keeps me going until the API is updated.