Mike Rockwell (Progress Software) asked a question.

HTML file of Device(s) attributes

Currently, there isn't a way to get a list of all attributes for all or a few devices. So I wrote this PowerShell script which will create an HTML file which you can put on a custom Dashboard view using the Free Form Text/HTML report. This takes advantage of the WhatsUpGoldPS PowerShell Module created by @Jason Alberino (Progress Software Company)​ . The script will check to see if WhatsUpGoldPS is installed, and install it for you, however, you may need to run it as Administrator. You should run this ON your WhatsUp Gold server, but you don't have to. Just enter the appropriate info to make it work, like your WUG server, and a userID and password.

 

  1. <#Checking to see if WhatsUpGoldPS module is installed,
  2. if not install it! You may have to run this with elevated permissions.#>
  3. if (-not (Get-Module -Name WhatsUpGoldPS)) {
  4. Import-Module WhatsUpGoldPS
  5. }
  6.  
  7. #Initialization Variables
  8. $wugServer = "LOCALHOST" #This is the hostname or IP address of your WUG server, if running on WUG server, use LOCALHOST
  9. $userID = "" #Enter a user who is has Access to WUG with API rights (API rights are the same as WUG user rights)
  10. $pwd = "" #Enter the password for the user. If you don't want to save it here, see this: https://pscustomobject.github.io/powershell/howto/Store-Credentials-in-PowerShell-Script/
  11.  
  12. $searchString = "1" #this is the search sting to find a specific device. 1 for all devices
  13.  
  14. #WUG regkeys - Don't modify these
  15. $regKey = 'HKLM:\SOFTWARE\Wow6432Node\Ipswitch\Nm.UI_WUG'
  16. $itemName = 'InstallDir'
  17.  
  18. #Output file path and file name
  19. $outFilePath = "" #if you are running this on the WUG server, you can leave it blank or otherwise put the path to save in
  20. $outFileName = "deviceAttributes.html" #you can change this if you want
  21.  
  22. #******Function to get path to WUG HTML if run on WUG server*****
  23. Function Get-RegistryValue ($regKey, $itemName) {
  24. $filePath = ""
  25. if ((Get-ItemProperty -Path $regKey -Name $itemName)) {
  26. $filePath = (Get-ItemProperty -Path $regKey -Name $itemName ).$itemName + "\NmConsole"
  27. }
  28. else {
  29. [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
  30. $title = 'Save File Path'
  31. $msg = 'Enter the path to save the file:'
  32. $filePath = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
  33. }
  34. return $FilePath
  35. }
  36. #*****End Function*****
  37.  
  38. #Setting the file path if run on the WUG Server
  39. if([string]::IsNullOrEmpty($outFilePath)){
  40. $outFilePath = Get-RegistryValue -regKey $regKey -itemName $itemName
  41. }
  42.  
  43. #building the PowerShell Credential
  44. $securePwd = ConvertTo-SecureString $pwd -AsPlainText -Force
  45. $cred = New-Object System.Management.Automation.PSCredential ($userID, $securePwd)
  46.  
  47. #Building the HTML to write to file - DON"T change this
  48. $htmlText = "<style> table {border-collapse: collapse;width: 100%;}th, td {text-align: left;padding: 8px;}tr[name='devices']:nth-child(odd) {background-color: Lightgrey;}</style><table>"
  49.  
  50. #Connecting to WUG API
  51. Connect-WUGServer -serverUri $wugServer -Credential $cred
  52.  
  53. #Getting the device(s)
  54. $devices = Get-WUGDevices -View card -SearchValue $searchString -Limit 500 | Select-Object id, name, networkAddress
  55. #Looping thought the devices returned
  56. foreach ($device in $devices) {
  57.  
  58. $htmlText += "<tr name='devices'><td><details><summary>$($device.name) : $($device.networkAddress)</summary><table>" #adding to the html to output
  59.  
  60. #Getting the deivce Attributes
  61. $devAttributes = Get-WUGDeviceAttributes -DeviceID $device.id | Select-Object name, value
  62.  
  63. #Looping through the attributes
  64. foreach ($attrib in $devAttributes){
  65. $htmlText += "<tr><td alight='right'>$($attrib.name)</td><td>$($attrib.value)</td></tr>"
  66. }
  67. $htmlText += "</table></details></td></tr>"
  68. }
  69. $htmlText += "</table>"
  70.  
  71. #Writing the output file
  72. Out-File -FilePath ($outFilePath + "\" + $outFileName) -InputObject $htmlText

If you add the Free Form Text/HTML report, click on the </> button and enter this

  1. <iframe src="/deviceAttributes.html" width="100%" height="100%"></iframe>

That is if you used the default file name. If you changed the name, well, change it here too.


Jason Alberino likes this.