WUG.ninja

Search

How do I automate refreshing device details in v2016 and below?

It took me a while to arrive at the final script here. I tried various different methods for automating this task but found this one to be the most effective. I was able to test this by running the script as a Windows scheduled task on my WhatsUp® Gold server and found it to be successful multiple days in a row now. This is PowerShell code which can be used as a Windows Scheduled task, I have a sample task .XML file included below as well. Note: This will only work with WUG 2016 and below!

$ErrorActionPreference = "Continue"
Clear-Variable *
#***Configuration
$username = "admin" #Username to login to web interface
$password = "Password1" #Password for the above user
$nDeviceGroupID = "2" #Device group ID of group you want to refresh devices in
#This can be grabbed through SQL by using select * from devicegroup
$url = "http://localhost/NmConsole/Workspace/HomeWorkspace/HomeWorkspace.asp?sUsername=$username&sPassword=$password" #URL for web interface
#***End Configuration
$ErrorActionPreference = "Continue"
$ie = New-Object -com InternetExplorer.Application
$IEpid = (Get-Process -Name iexplore).Id
Write-Host $pid
$ie.visible=$false
$ie.navigate("$url")
while($ie.ReadyState -ne 4) {start-sleep 2}
start-sleep 5
$timestamp = [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds
$url = 'http://localhost/NmConsole/$Nm/Core/Form-AspForms/inc/OpenJsDialog.asp?url=%2FNmConsole%2FWhatsConnected%2FDlgLayer2Rediscover%2FDlgLayer2Rediscover.asp&inParams={%22nGroupID%22:%22'+$nDeviceGroupID+'%22,%22nDeviceIDs%22:[]}&timestamp='+$timestamp+' HTTP/1.1'
$ie.navigate("$url")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
start-sleep 5
$Complete = ''
$count = 0
while($count -le 6)
{$Complete = $ie.document.getElementById("textDiscoveryStatus").value
$Devices = $ie.document.getElementById("textDeviceCount").value
start-sleep -Seconds 10
$count = $count + 1}
$Devices | Out-File C:rediscoverdevices.txt
$ie.quit()
taskkill /PID $pid /F

XML to import as Windows Scheduled Task

You can also download the XML to import as Windows Scheduled Task

Share This Post

More To Explore

WhatsUp Gold

WhatsUp Gold Tip #3: Monitor your systems

Focus on what is important It’s nice to have detailed monitoring information for every system on your network, but if a non-critical system is unavailable

Blog Posts

WhatsUp Gold Tip #2: Discover your systems

Introduction When you finish adding your credentials to WhatsUp Gold, the next step to success is configuring the discovery process in WhatsUp Gold to work for you.

credentials
Blog Posts

WhatsUp Gold Tip #1: Add your credentials first

Introduction Following installation, the first step to success is adding credentials for your infrastructure. WhatsUp Gold Network Monitoring and Log Management is an agentless solution