7 Replies Latest reply on Mar 20, 2017 11:55 AM by nick_scott

    Assign Custom Properties

    nick_scott

      I would like to assign custom properties to the nodes found via query.  As an example I would like to assign all devices in the 10.22.0.0/16 range the custom property Environment "QA".  The custom properties are already in place.  The script returns the Uri's I am after.  I do not know how to assign the new custom properties however.  

       

      $ErrorActionPreference = 'Stop'

       

      #Add the snapin
      Add-PSSnapin SwisSnapin

       

      #create a connection to solarwinds

      $hostname = 'xx'
      $username = 'xx'
      $password = 'XX'

       

      #swis = Connect-Swis -Hostanme $hostname -Trusted

       

      $swis = Connect-Swis -Hostname $hostname -Username $username -Password $password

       

      $query = Get-SwisData $swis "SELECT uri FROM Orion.Nodes WHERE ip_address LIKE '10.22.%'"

       

      $query

       

      swis://XX.net/Orion/Orion.Nodes/NodeID=151
      swis://XX.net/Orion/Orion.Nodes/NodeID=116
      swis://XX.net/Orion/Orion.Nodes/NodeID=146

        • Re: Assign Custom Properties
          HerrDoktor

          The Verb you are looking for is Set-SwisObject

          It might look like this then

           

          foreach($Entry in $query){
              ## Create CustomPropertiesURI ##
              $CustomPropsUri = $entry+'/CustomProperties';
          
              ##Set CustomPropertyBag
              $CustomPropstoUpdate = @{
                                      Environment = "QA";
                                  }
          
              ## Update the Custom Properties
              Set-SwisObject $swis $CustomPropsUri -Properties $CustomPropstoUpdate
          
          }
          
          
          

           

          Cheers,

          Holger

          1 of 1 people found this helpful
            • Re: Assign Custom Properties
              tdanner

              You can also do this as a bulk operation. For larger numbers of objects it is much faster. Like this:

               

              $swis = Connect-Swis -Hostname $hostname -Username $username -Password $password

              $CustomPropstoUpdate = @{  Environment = "QA";  }

              $uris = Get-SwisData $swis "SELECT Nodes.CustomProperties.Uri FROM Orion.Nodes WHERE ip_address LIKE '10.22.%'"

              $uris | Set-SwisObject $swis -Properties $CustomPropstoUpdate

               

               

              (Edit 2017-03-20: Added the "-Properties" switch that I forgot the first time around.)

              2 of 2 people found this helpful
                • Re: Assign Custom Properties
                  nick_scott

                  You are the man tdanner !  That's exactly what I was looking for.  Thank you!!

                   

                  I would be editing hundreds if not thousands of records.

                  • Re: Assign Custom Properties
                    HerrDoktor

                    Thanks for the Input. I might need to rewrite some of my scripts ...

                    • Re: Assign Custom Properties
                      nick_scott

                      My script pulls the various Uri's I am after, however  the script it stopping, and asking for a Properties value

                       

                      $swis = Connect-Swis -Hostname $hostname -Username $username -Password $password

                      $CustomPropertyUpdate =@{ Environment = "QA"; }

                      $uris = Get-SwisData $swis "SELECT uri FROM Orion.Nodes WHERE ip_address LIKE '10.1.%"

                      $uris | Set-SwisObject $swis $CustomPropertyUpdate

                       

                      #Error Below

                       

                      PS C:\Users\XXX> C:\Users\XXX.XXX\Documents\PowerShell Scripts\Do not Modify\Assign Enviorment Custom Property QA.ps1

                      cmdlet Set-SwisObject at command pipeline position 1

                      Supply values for the following parameters:

                      Properties:

                       

                      I put the value 'QA' (wild guess) and it errored out.  Any help would be appreciated.

                        • Re: Assign Custom Properties
                          tdanner

                          That's my fault - I left out the switch name in the Set-SwisObject line. Here's a fixed version:

                           

                          $swis = Connect-Swis -Hostname $hostname -Username $username -Password $password

                          $CustomPropertyUpdate =@{ Environment = "QA"; }

                          $uris = Get-SwisData $swis "SELECT uri FROM Orion.Nodes WHERE ip_address LIKE '10.1.%"

                          $uris | Set-SwisObject $swis -Properties $CustomPropertyUpdate

                           

                           

                          (I am going to edit my post above to save future readers from the error.)

                            • Re: Assign Custom Properties
                              nick_scott

                              Thank you tdanner!  That did the trick.  Being somewhat new to scripting, I am finding that its quite easy to replicate repetitive tasks (especially when using the "bulk" format tdanner advised in this post).  I do have a decent understanding of the DB schema however.  Just thought I would mention that considering most of you helping have XX years of programming experience.

                               

                              Going forward anytime something new comes across my desk, I am asking myself.  "Can I do this via the API ?"

                               

                              Thanks again for the help, I am really enjoying this!