15 Replies Latest reply on Jun 2, 2015 5:51 AM by madhavan

    Using Powershell to add nodes with Custom Properties for Device Type

    kjustin1996

      Hello,
      Running Orion NPM 10.6.0 and SDK 1.7 on Win2k8R2

       

      Can anyone help with adding devices into Orion using Powershell?

       

      To complete via NPM Web console, select Management, Edit Node.
      Select groups, break down the group to a specific node.
      Choose node properties, then edit node.
      Custom properties show Device_Type:

      12-4-2013 3-35-46 PM.png

       

      Sample script adding a server fails for the custom properties:
      ---------------

      Add-PSSnapin SwisSnapin

      # initialize SWIS connection
      $swis = Connect-Swis -Certificate

      # add a node
      $newNodeProps = @
      {
      EntityType="Orion.NodesCustomProperties";
      DisplayName="servername_here";
      Device_Type="Server_Windows";
      }

      $newNodeUri = New-SwisObject $swis –EntityType "Orion.NodesCustomProperties" –Properties $newNodeProps

      $nodeProps = Get-SwisObject $swis -Uri $newNodeUri Orion.Nodes

      Output:
      PS C:\> $newNodeUri = New-SwisObject $swis -EntityType "Orion.NodesCustomProperties" -Properties $newNodeProps
      New-SwisObject : Cannot bind argument to parameter 'Properties' because it is null.
      At line:1 char:89
      + $newNodeUri = New-SwisObject $swis -EntityType "Orion.NodesCustomProperties" -Properties <<<<  $newNodeProps
          + CategoryInfo          : InvalidData: (:) [New-SwisObject], ParameterBindingValidationException
          + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SwisPowerShell.NewSwisObject

      PS C:\>


      Similar blog = http://thwack.solarwinds.com/message/163190#163190

        • Re: Using Powershell to add nodes with Custom Properties for Device Type
          kjustin1996

          Anyone out there using NPM 10.6 with the SDK 1.7 to add and remove devices?

          Support says SDK 1.8 supports NPM 10.6, any way to get a pre-release candidate if it's not GA as yet?

           

          Trying simple device adds and removes fails, what SDK can I use?

           

          Using the supplied examples with the SDK (CRUD.AddNode) is the basis, but the PowerShell output shows errors.

           

          # Parameters required for command line
          param($device)

          $device

          # add a node
          $newNodeProps = @{
            EntityType="Orion.Nodes";
            IPAddress="10.0.0.1";
            IPAddressGUID="0100000a-0000-0000-0000-000000000000";
            Caption="$device";
            DynamicIP=$False;
            EngineID=1;
            Status=1;
            UnManaged=$False;
            Allow64BitCounters=$False;
            SysObjectID="";
            MachineType="";
            VendorIcon="";
            # SNMP v2 specific
            ObjectSubType="SNMP";
            SNMPVersion=2;
            Community="public";
            # polling timing (optional)
            RediscoveryInterval=5; # minutes (5..525600=1 year)
            PollInterval=120; # seconds (1..1200)
            StatCollection=10; # minutes (1..600)
          }

          $newNodeProps

          $newNodeUri = New-SwisObject $swis –EntityType "Orion.Nodes" –Properties $newNodeProps

          $nodeProps = Get-SwisObject $swis -Uri $newNodeUri

           

          Example output of CRUD.AddNode

           

          PS C:\Monadmin\scripts> .\addcrud.ps1 servernamehere

           

          servernamehere

           

          Name                           Value
          ----                           -----
          VendorIcon
          Caption                        servernamehere

          SysObjectID
          Community                      public
          Status                         1
          IPAddressGUID                  0100000a-0000-0000-0000-000000000000
          IPAddress                      10.0.0.1
          StatCollection                 10
          ObjectSubType                  SNMP
          PollInterval                   120
          SNMPVersion                    2
          Allow64BitCounters             False
          MachineType
          EntityType                     Orion.Nodes
          DynamicIP                      False
          EngineID                       1
          UnManaged                      False
          RediscoveryInterval            5
          Get-SwisObject : Could not find file 'C:\Users\adm_kjustin\AppData\Local\Temp\2\c7npslha.dll'.
          At C:\Monadmin\scripts\addcrud.ps1:36 char:28
          + $nodeProps = Get-SwisObject <<<<  $swis -Uri $newNodeUri
              + CategoryInfo          : NotSpecified: (:) [Get-SwisObject], FileNotFoundException
              + FullyQualifiedErrorId : System.IO.FileNotFoundException,SwisPowerShell.GetSwisObject

           

          The simple PowerShell below gives a 'Uri' null error

          # add a node Properties
          $newNodeProps = @{
          CustomProperties = @{
            DisplayName="servername_here";
            Device_Type="Server_Windows"; }
          }

          $newNodeUri = New-SwisObject $swis –EntityType "Orion.Nodes" –Properties $newNodeProps

          # Testing = Get-SwisObject $swis -Uri 'swis://localhost/Orion/Orion.Nodes/NodeID=3393/CustomProperties'
          #

          $nodeProps = Get-SwisObject $swis -Uri $newNodeUri Orion.Nodes

           

          Example output of simpler NPM AddNode

           

          PS C:\Monadmin\scripts>   .\addtest.ps1 servernamehere

           

          servernamehere

           

          Name                           Value
          ----                           -----
          CustomProperties               {DisplayName, Device_Type}
          EntityType                     Orion.Nodes
          Caption                        servernamehere

          New-SwisObject : No mapping exists from object type SolarWinds.InformationService.Addons.PropertyBag to a known managed provider native type.
          At C:\Monadmin\scripts\addtest.ps1:19 char:29
          + $newNodeUri = New-SwisObject <<<<  $swis -EntityType "Orion.Nodes" -Properties $newNodeProps
              + CategoryInfo          : InvalidOperation: (:) [New-SwisObject], FaultException`1
              + FullyQualifiedErrorId : SwisError,SwisPowerShell.NewSwisObject
          Get-SwisObject : Cannot bind argument to parameter 'Uri' because it is null.
          At C:\Monadmin\scripts\addtest.ps1:23 char:39
          + $nodeProps = Get-SwisObject $swis -Uri <<<<  $newNodeUri Orion.Nodes
              + CategoryInfo          : InvalidData: (:) [Get-SwisObject], ParameterBindingValidationException
              + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SwisPowerShell.GetSwisObject

          • Re: Using Powershell to add nodes with Custom Properties for Device Type
            lcoursy

            Maybe a simple question, but where do you call the script, in SWIS? I have one that I want to try, but I'm having the darndest time finding a step by step or gathering the information I need to attempt to test automation.