Hi everyone,
I'm hoping the community can help me with a SWIS API workflow that isn't behaving as I expect.
Goal:
I'm trying to programmatically perform a "List Resources" action using the PowerShell SDK to get a list of all available resources on a node.
My Environment:
- SolarWinds Platform: 1.1
- PowerShell SDK Module: 2.0.50049
- PowerShell Version: 5.1 (using the PowerShell ISE)
My Process:
I am following the standard asynchronous workflow (ScheduleListResources -> GetScheduledListResourcesStatus -> ImportListResourcesResult).
The first two steps work perfectly. ScheduleListResources returns a valid JobID, and I can poll GetScheduledListResourcesStatus until the status correctly reports as ReadyForImport.
The Issue:
I'm running into a problem on the final step. When I call ImportListResourcesResult, I receive a simple boolean true back (as <Return>true</Return>) instead of the detailed XML object containing the resource list that I was expecting based on documentation and other examples.
For additional context, when I check the Orion.InformationService.log file after running the script, I don't see any entry for the ImportListResourcesResult call, although I do see the entries for the preceding steps.
My Question:
Can anyone see what I might be doing wrong here? Is there a different approach or verb I should be using on Platform 2025.1.1 to get the results of a resource discovery? I feel like I'm missing a step, and any guidance would be greatly appreciated.
#Requires -Module SwisPowerShell
<#
DESCRIPTION
This script is for demonstrating an issue where the ImportListResourcesResult verb
does not return the expected XML data on certain modern platform versions.
#>
#------------------------------------------------------------------------------------
# ## --- USER-DEFINED VARIABLES --- ##
# ## --- EDIT THESE VALUES --- ##
#------------------------------------------------------------------------------------
#
Set the hostname of your Main SolarWinds Orion server.
$SolarWindsHost = "orion.example.com"
#
Set the NodeID you want to test against.
$NodeID = 12345
#------------------------------------------------------------------------------------
# ## --- SCRIPT LOGIC --- ##
#------------------------------------------------------------------------------------
try {
# Get Credentials and Connect to SWIS. This now uses the built-in Get-Credential command.
$swisCredential = Get-Credential -Message "Enter credentials for SolarWinds API ($SolarWindsHost)"
if (-not $swisCredential) { throw "Credentials were not provided." }
Write-Host "Connecting to SWIS on $SolarWindsHost..." -ForegroundColor Cyan
$swis = Connect-Swis -Host $SolarWindsHost -Credential $swisCredential
Write-Host "Successfully connected."
# ---------------------------------------------------------------------------------
# STEP 1: Schedule the Discovery Job.
# LOGIC: Call the standard verb to kick off a "List Resources" discovery in the background.
# EXPECTATION: A string JobID is returned.
# ---------------------------------------------------------------------------------
Write-Host "`nSTEP 1: Calling 'ScheduleListResources' for NodeID $NodeID..." -ForegroundColor Cyan
$jobIdObject = Invoke-SwisVerb -SwisConnection $swis -EntityName "Orion.Nodes" -Verb "ScheduleListResources" -Arguments @($NodeID)
$jobId = ""
if ($jobIdObject -is [System.Xml.XmlElement]) { $jobId = $jobIdObject.'#text' } else { $jobId = $jobIdObject }
if (-not $jobId) { throw "Failed to schedule the discovery job." }
Write-Host "--> Success. Discovery job scheduled. JobID: $jobId"
# ---------------------------------------------------------------------------------
# STEP 2: Poll for Job Completion.
# LOGIC: Call the status verb in a loop until the job is complete.
# EXPECTATION: The status string should change from 'InProgress' to 'ReadyForImport'.
# ---------------------------------------------------------------------------------
Write-Host "`nSTEP 2: Polling job status using 'GetScheduledListResourcesStatus'..." -ForegroundColor Cyan
$timeoutSeconds = 300
$pollingIntervalSeconds = 5
$elapsedSeconds = 0
$statusText = ""
while ($elapsedSeconds -lt $timeoutSeconds) {
$statusObject = Invoke-SwisVerb -SwisConnection $swis -EntityName "Orion.Nodes" -Verb "GetScheduledListResourcesStatus" -Arguments @($jobId, $NodeID)
if ($statusObject -is [System.Xml.XmlElement]) { $statusText = $statusObject.'#text' } else { $statusText = $statusObject }
Write-Host " - Current status is '$statusText'..."
if ($statusText -eq "ReadyForImport") {
Write-Host "--> Success. Job is complete."
break
}
Start-Sleep -Seconds $pollingIntervalSeconds
$elapsedSeconds += $pollingIntervalSeconds
}
if ($statusText -ne "ReadyForImport") {
throw "Timed out waiting for discovery job to complete."
}
# ---------------------------------------------------------------------------------
# STEP 3: Retrieve the Discovery Results.
# LOGIC: Call the verb to retrieve the results of the completed discovery job.
# EXPECTED BEHAVIOR: A detailed XML object containing the list of all available resources.
# ACTUAL BEHAVIOR: The verb returns a simple boolean 'true', and the server does
# not log the transaction. This is the core of the issue.
# ---------------------------------------------------------------------------------
Write-Host "`nSTEP 3: Calling 'ImportListResourcesResult' to get the final data..." -ForegroundColor Cyan
$importResultXml = Invoke-SwisVerb -SwisConnection $swis -EntityName "Orion.Nodes" -Verb "ImportListResourcesResult" -Arguments @($jobId, $NodeID)
# --- This section prints the raw output for diagnosis ---
Write-Host "`n------------------------------------------------------------" -ForegroundColor Yellow
Write-Host " RAW XML OUTPUT FROM THE FINAL COMMAND:" -ForegroundColor Yellow
Write-Host "------------------------------------------------------------" -ForegroundColor Yellow
if ($importResultXml) {
$importResultXml.OuterXml | Write-Output
} else {
Write-Host "--> ERROR: The command returned no data ($null)." -ForegroundColor Red
}
}
catch {
Write-Error "The script failed. Error: $_"
}
Write-Host "`n`nScript demonstration finished."
Thank you!