2 Replies Latest reply on Apr 16, 2015 5:08 AM by lynchnigel

    Accessing Nodecustomproperties in a powershell script

    lynchnigel

      hi all

      Im trying to get a grips of this but failing. Ive had this script working before the latest update when i think the Node Custom Properties was moved to another table and i'm having problems writing to that table with the entity

       

      Any pointers, or easier way or right way of doing this is most appreciated

       

      The script so far looks like this and basically enables me to copy the wireless AP name from the wireless AP table to a newly discovered node (runs every night) along with putting a comment into a custom comment field in the 'NodeCustomProperties' table

       

      # Load the SwisSnapin if not already loaded

      if (!(Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {

          Add-PSSnapin "SwisSnapin"

      }

       

      $swis = Connect-Swis –Trusted –Hostname localhost # create a SWIS connection object

       

      $nodedetails = Get-SwisData $swis "SELECT Uri, IPAddress, Caption, NodeID FROM Orion.Nodes"

       

      foreach ($nodedetail in $nodedetails) {

       

         #Gets the AP

           $WirelessDetail = Get-SwisData $swis "SELECT Uri, DisplayName, IPAddress FROM Orion.Packages.Wireless.AccessPoints WHERE IPAddress =     @IPAddress" @{IPAddress=$nodedetail.IPAddress}

       

                      if ($nodedetail.IPaddress -ne '0.0.0.0') {

                   if ($WirelessDetail -ne $null) {

       

      #Counts assigned wifi nodes                  

                          $Count_Nodes = $Count_Nodes +1

      # shows my what its found.

      Write-Host "found nodedetail" $Nodedetail.caption $nodedetail.IPAddress "(" $WirelessDetail.IPAddress  $WirelessDetail.DisplayName  ")"

       

       

      #gets the custom comments field for the record

                      $sourceNodeProps = Get-SwisData $swis "SELECT Comments AS NodeComment FROM Orion.NodesCustomProperties Where NodeID = @nodeid" @{nodeid=$nodedetail.Nodeid}

                     

                        #################This is the bit that I cant get working  writing  back the custom comment ####################################                            

                       $nodedetail.Uri|Set-SwisObject $swis $sourceNodeProps = "AP"

                       ############################################################################

       

       

      ######### This works and fills in the  display name /caption ########

          $nodedetail.Uri|Set-SwisObject $swis -Properties @{Caption = $WirelessDetail.DisplayName} ;

                     

                         continue

                        } # End If -$wirelessdetail is enpty

                      } #End IF the IP is 0.0.0.0

       

               } #end of for loop

                        

          Write-Host "found and Assigned " $Count_Nodes "Wifi Nodes"