2 Replies Latest reply on Oct 3, 2016 12:28 PM by fourmica

    Deleting an Orion Agent and its Node using Powershell SDK instead of GUI

    fourmica

      I want to replicate the behavior in the GUI that occurs if I go to:

       

      https://myOrionServer/Orion/AgentManagement/Admin/ManageAgents.aspx

       

      Select an Agent, and click Delete. This not only removes the Agent registration, it also deletes the Node and cleans up everything associated with it.

       

      I THINK the correct way to do that with Powershell is:

       

      invoke-swisverb $swis Orion.AgentManagement.Agent delete @($agentid)

       

      Where $swis is the SwisConnection, Orion.AgentManagement.Agent is the Entity, delete is the Verb, and $agentid is the integer in the AgentId column in the Orion.AgentManagement.Agent table.

       

      Am I correct in my syntax? Will this accomplish the same thing that using the GUI does when I select an Agent and click Delete? If not, what else would I need to do?

        • Re: Deleting an Orion Agent and its Node using Powershell SDK instead of GUI
          tdanner

          In the API, deleting the agent and deleting the associated node are two separate operations. The agent management UI combines them.

           

          Your PowerShell for deleting the agent looks correct. You can also do it by getting the Uri for the agent record and calling "Remove-SwisObject $swis $agentUri" on it. It leads to the same place.

           

          To delete the Node, you need the Uri for the node. Given the agent ID, you can get the node Uri with a query like this:

           

          SELECT Agent.Node.Uri AS Uri

          FROM Orion.AgentManagement.Agent

          WHERE AgentId = 1234

           

          (Note that you need to run this query before you delete the agent, because it won't work after!)

           

          Then you can remove the node like this:

           

          Remove-SwisObject $swis $nodeUri