5 Replies Latest reply on Mar 28, 2017 9:55 AM by tdanner

    [Q] Batch Editing Custom Properties w/ Powershell

    capetocairo

      We are trying to utilize Powershell to be able to update multiple custom properties of a specific subnet of machines. We have used the guidance found on the Github regarding most of the syntax, but we are still getting an error message when we run the entire sequence.

       

      Here is the body of the script; I have redacted some things for obvious reasons:

       

      #Intialization
      Add-PSSNapin SwisSnapin

       

      # Connect to SWIS
      $hostname = "xxx.xxx.xxx.xxx"
      $username = "UserName"
      $password = get-content C:\Path\To\PWinfo.txt | convertto-securestring
      $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
      $swis = Connect-Swis -host $hostname -cred $cred

       

      $NodeID="SELECT NodeID FROM Orion.Nodes WHERE IP_Address LIKE 'xxx.xxx.xxx.%'" # NodeID of a node which custom properties you want to change

       

      # prepare a custom property value
      $customProps = @{
        Comments="TEST comment - Delete Me";
        SecondarySiteEmail="test.email@testemail.com"
        ESN="TEST - numbers"
      }

       

      # build the node URI
      $uri = "swis://localhost/Orion/Orion.Nodes/NodeID=$nodeId/CustomProperties";
      # set the custom property
      $NodeID2="SELECT NodeID FROM Orion.Nodes WHERE IP_Address LIKE '10.98.108.%'" | Set-SwisObject $swis -Uri $uri -Properties $customProps

       

      However, the error message we are getting is this: "The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input."

       

      We were under the assumption that piping this was necessary, but we are re-thinking this. Any suggestions on what we are missing here?

        • Re: [Q] Batch Editing Custom Properties w/ Powershell
          tdanner

          Set-SwisObject needs one or more Uris that specify which objects to update. There are two ways to supply Uri(s) to Set-SwisObject:

           

          1. Using the "-Uri" option.

          2. As pipeline input. This method allows you to send many Uris - Set-SwisObject is smart enough to send them all to Orion as a single batch, saving a significant amount of time as compared to sending each one separately.

           

          You are attempting to use both methods at once and PowerShell is getting confused. Since you are updating a whole /24 of nodes at once, you should use method #2. Here's how I would write your script:

           

          #Intialization
          Add-PSSNapin SwisSnapin
          
          # Connect to SWIS
          $hostname = "xxx.xxx.xxx.xxx"
          $username = "UserName"
          $password = get-content C:\Path\To\PWinfo.txt | convertto-securestring
          $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
          $swis = Connect-Swis -host $hostname -cred $cred
          
          # prepare a custom property value
          $customProps = @{
            Comments="TEST comment - Delete Me";
            SecondarySiteEmail="test.email@testemail.com"
            ESN="TEST - numbers"
          }
          
          # set the custom property
          $uris = Get-SwisData $swis "SELECT Uri FROM Orion.Nodes WHERE IP_Address LIKE '10.98.108.%'"
          $uris | Set-SwisObject $swis -Properties $customProps
          

           

          Rather than select NodeID and then use string formatting to build up the Uri, I just ask SWIS for the complete Uri instead.