5 Replies Latest reply on Feb 20, 2017 2:13 PM by Steven Klassen

    Using RemoveDependencies Verb

    Steven Klassen

      Hi all,

       

      I'm trying to use the RemoveDependencies verb from the Orion.Dependencies entity.

       

       

      It's asking for an array of integers (System.Int32[]) and I tried doing the following:

       

      1. Passing the array of DependencyID values in via pipe (e.g., $depIDs | Invoke-SwisVerb...)
      2. Passing them as an argument (below).
      3. Passing them in one at a time in their own single element array (below).

       

      Option #1

      $depIDs | Invoke-SwisVerb $swis Orion.Dependencies RemoveDependencies
      

       

      Option #2

      $depIDs = Get-SwisData $swis 'SELECT DependencyID FROM Orion.Dependencies'
      Invoke-SwisVerb $swis Orion.Dependencies RemoveDependencies $depIDs
      

       

      Option #3

      $depIDs = Get-SwisData $swis 'SELECT DependencyID FROM Orion.Dependencies'
      foreach ($id in $depIDs) {
          Invoke-SwisVerb $swis Orion.Dependencies RemoveDependencies @($id)
      }
      

       

      Option #1 complains about a missing parameter and options #2 and #3 complain about not being able to unpack argument 0.

       

      Thanks for the help in advance!

        • Re: Using RemoveDependencies Verb
          tdanner

          Invoke-SwisVerb needs an array of argument values. If the verb in question takes only one argument (like RemoveDependencies does), then you need to supply an array of one argument. The argument type needs to match (or at least be "close enough" for SWIS to convert it to) the verbs parameter type, which is an array of ints here. You have your array of ints in $depIDs.

           

          In option #1 you sent it through the PowerShell pipeline. Invoke-SwisVerb doesn't look at the pipeline (though Set-SwisObject and Remove-SwisObject will accept Uris through the pipeline), so that didn't work. PowerShell complains because the "-Arguments" parameter (fourth positional parameter) is required.

           

          In option #2 you provided an array, but it doesn't contain an array of ints - it contains several ints. SWIS tries to convert the first int to an array of ints, but this fails.

           

          In option #3 you provided an array, but it doesn't contain an array of ints - it contains a single int. SWIS tries to convert the first int to an array of ints, but this fails.

           

          At this point the logical thing to do is to wrap $depIDs like this: @( $depIDs ). Unfortunately PowerShell tries to be too clever here. Instead of making what we want (an array of an array) it unrolls $depIDs into another list. To get what we want, you use this weird syntax:

           

          @( , $depIDs )

           

          Yes, that is a comma before $depIDs.