Network Management
Update multiple resources on agent nodes
This article discusses how to update all resources on agent nodes.
First published date
Last published date
Overview
Product section
Resolution
To update resources on agent nodes:
-
Save the following powershell script, customize it, and run it.
<# -- Scripts are not supported under any SolarWinds support program or service. -- Scripts are provided AS IS without warranty of any kind. SolarWinds further -- disclaims all warranties including, without limitation, any implied warranties -- of merchantability or of fitness for a particular purpose. The risk arising -- out of the use or performance of the scripts and documentation stays with you. -- In no event shall SolarWinds or anyone else involved in the creation, -- production, or delivery of the scripts be liable for any damages whatsoever -- (including, without limitation, damages for loss of business profits, business -- interruption, loss of business information, or other pecuniary loss) arising -- out of the use of or inability to use the scripts or documentation. .EXAMPLE $swis = Connect-Swis -Hostname localhost -UserName Admin -Password 123 .\ImportListResources.ps1 $swis 1 60 .EXAMPLE $swis = Connect-Swis -Hostname localhost -UserName Admin -Password 123 .\ImportListResources.ps1 -nodeId 1 -swis $swis -timeBetweenChecks 3 .SYNOPSIS This is a simple Powershell script to import list resources of given node .DESCRIPTION The script itself will start ListResources job, waits until job is done and import results .LINK Prerequisits: https://www.powershellgallery.com/packages/SwisPowerShell #> [CmdletBinding()] Param( [Parameter(Position=0,mandatory=$true)] # Swis connection created via Connect-Swis command [Object]$swis, [Parameter(Position=1,mandatory=$true)] # ID of node to import resources [int]$nodeId, [Parameter(Position=2,mandatory=$false)] # Timeout in seconds for wait for 'ReadyForImport' status [int]$timeout = 30, [Parameter(Position=3,mandatory=$false)] # Time to wait before next status check [int]$timeBetweenChecks = 2 ) # It takes a while before job will turn to 'InProgress' status from 'Unknown' $ensureJobWasCreatedWait = 3 $sw = [diagnostics.stopwatch]::StartNew() Write-Host ("Creating schedule list resources job...") do { if ($sw.Elapsed.TotalSeconds -gt $timeout) { throw ("Timeout elapsed when crating job. This is probably caused by calling this script with same nodeId. Please wait few minutes or extend timeout.") } $result = Invoke-SwisVerb $swis "orion.nodes" "ScheduleListResources" @($nodeId) $jobId = $result.'#text' Write-Debug ("Created job with guid: " + $jobId) Start-Sleep -Seconds $ensureJobWasCreatedWait $status = Invoke-SwisVerb $swis "orion.nodes" "GetScheduledListResourcesStatus" @($jobId, $nodeId) Write-Debug ("Job status is: " + $status.'#text') } while ($status.'#text' -eq "Unknown") Write-Host ("Waiting until job status will be 'ReadyForImport'...") while ($status.'#text' -ne "ReadyForImport") { if ($sw.Elapsed.TotalSeconds -gt $timeout) { throw ("Timeout elapsed when waiting for status 'ReadyForImport'") } Start-Sleep -Seconds $timeBetweenChecks $status = Invoke-SwisVerb $swis "orion.nodes" "GetScheduledListResourcesStatus" @($jobId, $nodeId) Write-Debug ("Job status is: " + $status.'#text') } Write-Host ("Importing list resources...") $importResult = Invoke-SwisVerb $swis "orion.nodes" "ImportListResourcesResult" @($jobId, $nodeId) if (![System.Convert]::ToBoolean($importResult.'#text')) { throw ("Import of ListResources result for NodeId:" + $nodeId + " finished with errors.") } Write-Host -ForegroundColor Green ("Script finished successfully")To find more details on using scripts with SolarWinds Platform products, visit THWACK, the SolarWinds IT community forum.