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.

Power shell to add node to SAM

here is the script I am running...

# This sample script shows how to use the Orion Discovery API to discover and import one node using WMI credentials.

# Load SwisPowerShell
Import-Module SwisPowerShell

# Swis connection info
$OrionServer = "localhost"
$Username = "#######"
$Password = "############################"

# Discovery parameters
$ip = "10.40.52.13"
$wmiCredentialsName = '#################'
$engindId = 1
$DeleteProfileAfterDiscoveryCompletes = "true"

$swis = Connect-Swis $OrionServer -UserName $Username -Password $Password

# Get the ID of the named WMI credential
$wmiCredentialsId= Get-SwisData $swis "SELECT ID FROM Orion.Credential WHERE Name=@name" @{name = $wmiCredentialsName}

$CorePluginConfigurationContext = ([xml]"
<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<BulkList>
<IpAddress>
<Address>$ip</Address>
</IpAddress>
</BulkList>
<Credentials>
<SharedCredentialInfo>
<CredentialID>$wmiCredentialsId</CredentialID>
<Order>1</Order>
</SharedCredentialInfo>
</Credentials>
<WmiRetriesCount>1</WmiRetriesCount>
<WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds>
</CorePluginConfigurationContext>
").DocumentElement

$CorePluginConfiguration = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginConfiguration @($CorePluginConfigurationContext)

$StartDiscoveryContext = ([xml]"
<StartDiscoveryContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<Name>Script Discovery $([DateTime]::Now)</Name>
<EngineId>$engindId</EngineId>
<JobTimeoutSeconds>3600</JobTimeoutSeconds>
<SearchTimeoutMiliseconds>2000</SearchTimeoutMiliseconds>
<SnmpTimeoutMiliseconds>2000</SnmpTimeoutMiliseconds>
<SnmpRetries>1</SnmpRetries>
<RepeatIntervalMiliseconds>1500</RepeatIntervalMiliseconds>
<SnmpPort>161</SnmpPort>
<HopCount>0</HopCount>
<PreferredSnmpVersion>SNMP2c</PreferredSnmpVersion>
<DisableIcmp>false</DisableIcmp>
<AllowDuplicateNodes>false</AllowDuplicateNodes>
<IsAutoImport>true</IsAutoImport>
<IsHidden>$DeleteProfileAfterDiscoveryCompletes</IsHidden>
<PreferredPollingMethod>1</PreferredPollingMethod>
<PluginConfigurations>
<PluginConfiguration>
<PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem>
</PluginConfiguration>
</PluginConfigurations>
</StartDiscoveryContext>
").DocumentElement

$DiscoveryProfileID = (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($StartDiscoveryContext)).InnerText

Write-Host -NoNewline "Discovery profile #$DiscoveryProfileID running..."

# Wait until the discovery completes
do {
Write-Host -NoNewline "."
Start-Sleep -Seconds 1
$Status = Get-SwisData $swis "SELECT Status FROM Orion.DiscoveryProfiles WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID}
} while ($Status -eq 1)

# If $DeleteProfileAfterDiscoveryCompletes is true, then the profile will be gone at this point, but we can still get the result from Orion.DiscoveryLogs

$Result = Get-SwisData $swis "SELECT Result, ResultDescription, ErrorMessage, BatchID FROM Orion.DiscoveryLogs WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID}

# Print the outcome
switch ($Result.Result) {
0 {"Unknown"}
1 {"InProgress"}
2 {"Finished"}
3 {"Error"}
4 {"NotScheduled"}
5 {"Scheduled"}
6 {"NotCompleted"}
7 {"Canceling"}
8 {"ReadyForImport"}
}
$Result.ResultDescription
$Result.ErrorMessage

if ($Result.Result -eq 2) { # if discovery completed successfully
# Find out what objects were discovered
$Discovered = Get-SwisData $swis "SELECT EntityType, DisplayName, NetObjectID FROM Orion.DiscoveryLogItems WHERE BatchID = @batchId" @{batchId = $Result.BatchID}
"$($Discovered.Count) items imported."
$Discovered
}

I am getting the below errors.

Invoke-SwisVerb : Verb Orion.Discovery.CreateCorePluginConfiguration cannot unpackage parameter 0 of type
SolarWinds.Data.Providers.Orion.Verbs.Discovery+CorePluginConfigurationContext
At C:\Users\Administrator\Desktop\add node .ps1:40 char:28
+ ... iguration = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginCon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-SwisVerb], FaultException`1
+ FullyQualifiedErrorId : SwisError,SwisPowerShell.InvokeSwisVerb
Invoke-SwisVerb : ProvideFault failed, check fault information.
At C:\Users\Administrator\Desktop\add node .ps1:67 char:24
+ ... rofileID = (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-SwisVerb], FaultException`1
+ FullyQualifiedErrorId : SwisError,SwisPowerShell.InvokeSwisVerb

This was a script off of GitHub, you would think it should work.....  Actually you would think SolarWinds themselves would have this script...

  • Hi VCF4theWIN,

    The  $CorePluginConfigurationContext XML looks okay, so I would check if the Credential ID is being properly resolved.
    Is $wmiCredentialsId being correctly assigned a value?

    Yaquaholic

  • I fixed it with a new script....

    # This sample script demonstrates how to add a new node using CRUD operations and add WMI Polling.
    # Please update the hostname and credential setup to match your configuration, and
    # information about the node you would like to add for monitoring.

    # Load SwisPowerShell
    Import-Module SwisPowerShell

    Clear-Host

    function AddPoller($PollerType) {
    $poller["PollerType"] = $PollerType
    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
    }

    # Connect to SWIS with default admin credentials
    $target="localhost"

    # change the username and password HERE!!!!!!!!!
    $swis = Connect-Swis -host $target -UserName admin -Password "CHANGE THIS!!!"

    #Change the IP address you want to add

    $ip = "10.40.52.13"
    $credentialName = "SA_ INVENTORY" # Enter here the name under which the WMI credentials are stored. You can find it in the "Manage Windows Credentials" section of the Orion website (Settings)

    # Node properties
    $newNodeProps = @{
    IPAddress = $ip
    EngineID = 1
    ObjectSubType = "WMI"

    DNS = "test"
    SysName = "test"
    }

    #Creating the node
    $newNodeUri = New-SwisObject $swis -EntityType "Orion.Nodes" -Properties $newNodeProps
    $nodeProps = Get-SwisObject $swis -Uri $newNodeUri

    #Getting the Credential ID
    $credentialId = Get-SwisData $swis "SELECT ID FROM Orion.Credential where Name = '$credentialName'"
    if (!$credentialId) {
    Throw "Can't find the Credential with the provided Credential name '$credentialName'."
    }

    #Adding NodeSettings
    $nodeSettings = @{
    NodeID = $nodeProps["NodeID"]
    SettingName = "WMICredential"
    SettingValue = ($credentialId.ToString())
    }

    #Creating node settings
    $newNodeSettings = New-SwisObject $swis -EntityType "Orion.NodeSettings" -Properties $nodeSettings

    # register specific pollers for the node
    $poller = @{
    NetObject = "N:" + $nodeProps["NodeID"]
    NetObjectType = "N"
    NetObjectID = $nodeProps["NodeID"]
    }

    #region Add Pollers for Status (Up/Down), Response Time, Details, Uptime, CPU, & Memory
    # Status
    $poller["PollerType"]="N.Status.ICMP.Native";
    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

    # Response time
    $poller["PollerType"]="N.ResponseTime.ICMP.Native";
    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

    # Details
    $poller["PollerType"]="N.Details.WMI.Vista";
    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

    # Uptime
    $poller["PollerType"]="N.Uptime.WMI.XP";
    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

    # CPU
    $poller["PollerType"]="N.Cpu.WMI.Windows";
    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

    # Memory
    $poller["PollerType"]="N.Memory.WMI.Windows";
    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
    #endregion Add Pollers for Status (Up/Down), Response Time, Details, Uptime, CPU, & Memory