I was really surprised and disappointed to see multiple posts in the API forum saying there is no API that can be used to add nodes with pre-installed agents. At our site we have decided, for security reasons, to use Orion agents in passive mode (server-initiated polling) for monitoring all Windows servers. And we install the agents using SCCM. So now I have the agent installed on >600 Windows servers and I discover there's no way to automate addition of those nodes in NPM. And the manual process is not pretty.
I did find it was surprisingly easy to build a PowerShell script that automates the actions in Internet Explorer (IE). I used IE because I can automate that from PowerShell with no additional software (Chrome or Edge would automation would require extra stuff).
Of course, the next update to NPM may break this.....
#
# A script to automate addition of nodes with pre-installed agents (e.g. Windows servers with agents installed by SCCM)
# using IE automation of the web interface. This is a fairly deperate solution to registering large numbers
# of pre-installed agents, as it seems there is no API do to this.
#
# This was developed and used with NPM 2020.2.5 and is very vulnerable to changes in the web interface.
#
# by Carlo Giuliani, June 2021
#
# URL of web console of your Solarwinds Orion instance
$BaseURL = 'https://solarwinds'
# Load CSV file containing list of servers
# Each row is assumed to contain one column with HOSTNAME and another with FQDN (which can actually be an IP address)
#
$List = 'H:\SolarWinds\database servers.csv'
$Servers = Import-CSV $List
If ($creds -eq $null) {$creds = Get-Credential 'domain\userid' -Message 'Provide credentials with permissions on Solarwinds' }
#
# Function to wait for IE navigation (page load) to complete
# Writes a "." every 200ms to you know something is going on.
#
Function WaitFor-IE { Param($Browser)
While($ie.Busy -or ($ie.ReadyState -ne 4) ) { Start-Sleep -milliseconds 200; Write-Host '.' -NoNewline }
Return $Browser.Document
}
# workaround for problem of losing COM connection when crossing IE security zones
$type = [Type]::GetTypeFromCLSID('D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E')
$ie = [System.Activator]::CreateInstance($Type)
# The window does not need to be visible, but it's handy for debugging
$ie.Visible = $true
# Open Solarwinds Orion and authenticate
$IE.Navigate($BaseUrl)
$Doc = WaitFor-IE $ie
$Doc.getElementById('ctl00_BodyContent_Username').Value = $creds.username
$Doc.getElementById('ctl00_BodyContent_Password').Value = $creds.GetNetworkCredential().Password
$Doc.getElementById('ctl00_BodyContent_LoginButton').Click()
$Doc = WaitFor-IE $ie
#
# Attempt to register agent for each row in the CSV file.
# Display and record any error messages.
#
$n = $Servers.count
ForEach ($i in (0..($Servers.count-1))) {
$s = $Servers[$i]
Write-Host "Adding $($s.FQDN) as $($s.Hostname) ($($i+1)/$n): " -NoNewline
$IE.Navigate("$BaseURL/Orion/AgentManagement/Admin/EditAgent.aspx")
$Doc = WaitFor-IE $ie
$Doc.getElementById('ctl00_ctl00_ctl00_ctl00_BodyContent_ContentPlaceHolder1_adminContentPlaceholder_adminContentPlaceholder_passiveRadio').Click()
$Doc.getElementById('ctl00_ctl00_ctl00_ctl00_BodyContent_ContentPlaceHolder1_adminContentPlaceholder_adminContentPlaceholder_nameBox').Value=($s.hostname)
$Doc.getElementById('ctl00_ctl00_ctl00_ctl00_BodyContent_ContentPlaceHolder1_adminContentPlaceholder_adminContentPlaceholder_passiveAgentHostnameBox').Value=$s.fqdn
$Submit = $Doc.Body.getElementsByClassName('sw-btn-primary') | select -first 1
$Submit.Click()
$Doc = WaitFor-IE $ie
$Errors = ( $Doc.Body.getElementsByClassName('sw-validation-error') | %{$_.TextContent -replace '\n',' '} | ?{$_.length -gt 0} ) -Join ' -- '
$Servers[$i] | Add-Member 'NoteProperty' 'Result' $Errors -EA 0
$i=$i+1
Write-Host $Errors
}
#
# Save file with results, in CSV file with'-results' appended to filename
#
$Servers | Export-CSV ($List -replace '.csv$','-results.csv') -NoTypeInformation
#
# Close browser
#
$IE.Quit()