Automate refreshing device/group details (Layer 2 and Inventory information)


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 *
$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
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'
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
taskkill /PID $pid /F


XML to import as Windows Scheduled Task

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

Post your comment