This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Using Powershell to add nodes with Custom Properties for Device Type

FormerMember
FormerMember

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

  • FormerMember
    0 FormerMember

    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

  • Hello kjustin,

    I'm not sure if you can set also the custom properties when creating the node. I hope somebody would answer it.

    You can try to create node first and set the custom property then. You can reffer to the sample script CRUD.SettingCustomProperty.ps1

    1. Create node (don't use custom properties in the $newNodeProps hashtable)

    2. When creating you'll get the $newNodeUri

    3.

    $CustomProperties = @{

      DisplayName="servername_here";

      Device_Type="Server_Windows"; }

    # set the custom property

    Set-SwisObject $swis -Uri  ($newNodeUri + '/CustomProperties') -Properties $CustomProperties

    Please let me know if this workaround helped. Otherwise, please create support ticket with all information you can give us so we can investigate the problem and possibly fix.

    However the error ('C:\Users\adm_kjustin\AppData\Local\Temp\2\c7npslha.dll'.) sounds weird to me. It could be possibly some problem with your SDK installation.

    Thanks.

  • You can add custom properties when creating the node, but I write this sort of thing in perl (because the linux servers with our CMDB on it don't support powershell).

  • FormerMember
    0 FormerMember in reply to RichardLetts

    Jan,

    Question on SDK provided CRUD.AddNode.ps1

    How do you specify the ICMP Only poller?

    When I look at Custom Properties, the poller doesn't show ICMP only, but as "Most Devices"

    12-13-2013 10-50-59 AM.png

    http://orion/Orion/Nodes/NodeProperties.aspx?Nodes=3557

    What is correct "PollerType" for Polling method to be "Status Only: ICMP"

    If I comment out the Details and Uptime poller lines, you get an error in the webconsole for the device (see image below)

    12-13-2013 10-42-34 AM.png

    Thanks,

    Kevin

  • The "Polling Method: Status Only: ICMP" radio button on the Add/Edit Node page corresponds to the ObjectSubType property of the Orion.Nodes entity being set to 'ICMP'.

  • FormerMember
    0 FormerMember in reply to tdanner

    Thank you sir, added the ObjectSubType="ICMP"; to the new node properties.

  • FormerMember
    0 FormerMember in reply to tdanner

    Trying to use this to remove and add node as DHCP. It will flip the flag for Dynamic IP Address without issue, but it isn't filling in the DNS Hostname to match the node name. Is there a parameter for this?

    Orion_DNS_Hostname.jpg

  • To create a "Dynamic IP" node, set the "DNS" property to the fqdn of the device and set the "DynamicIP" property to true. Within a few minutes Orion will resolve the DNS name, fill in the IP address properties, and start polling the device.

  • FormerMember
    0 FormerMember in reply to tdanner

    The works for adding the device, but once the device IP address changes Orion is not updating the IP. Is this because the DNS Hostname field does not populate when adding hosts with this script?

    When manually inputting a node and select “Dynamic IP Address DHCP or BOOTP” it does not allow you to leave the “DNS Hostname” field blank, but the script adds the node and leave “DNS Hostname” blank.

  • FormerMember
    0 FormerMember in reply to tdanner

    Tested and verified that node that is manually input with DNS Hostname field will update IP when it changes, but node input with this script will not. Assuming that it’s because the script inputs FQDN for “Name” field, but not “DNS Hostname” field. What variable we can add to script to enter this parameter for both fields?