Urgent help needed

I created a uddashboard to extract vmware cluster info real time. Not successful with get-stat realtime due to authentication issues. This script is working but not reloading … its static … i want the report whenever i refresh the web page… gurus, can you please help me… thanks

function get-clustersummary {
     Gets summary information from the cluster
     This function creates report with summary information of the cluster
     Source: Automating vSphere Administration
    .PARAMETER Cluster
     The cluster object to create a report on 
     PS> get-clustersummary -cluster (get-cluster CL01)
     PS> get-cluster|get-clustersummary

           HelpMessage="Enter a cluster entity")]
         [VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl] $cluster)
  $hosts = $cluster |get-vmhost

  [double]$cpuAverage = 0

  [double]$memAverage = 0

  foreach ($esx in $hosts) {

  [double]$esxiCPUavg = [double]($esx | Select-Object @{N = 'cpuAvg'; E = {[double]([math]::Round(($_.CpuUsageMhz) / ($_.CpuTotalMhz) * 100, 2))}} |Select-Object -ExpandProperty cpuAvg)

  $cpuAverage = $cpuAverage + $esxiCPUavg

  [double]$esxiMEMavg = [double]($esx | Select-Object @{N = 'memAvg'; E = {[double]([math]::Round(($_.MemoryUsageMB) / ($_.MemoryTotalMB) * 100, 2))}} |select-object -ExpandProperty memAvg)

  $memAverage = $memAverage + $esxiMEMavg


  $cpuAverage = [math]::Round(($cpuAverage / ($hosts.count) ), 1)

  $memAverage = [math]::Round(($memAverage / ($hosts.count) ), 1)

  $ClusterInfo = "" | Select-Object Name, NumHosts,NumCores,CPUThreads,TotalCPUGHz,TotalMemGB, CPUAvg, MEMAvg

  $ClusterInfo.Name = $cluster.Name

  $ClusterInfo.TotalCPUGHz="{0:n2}" -f ($cluster.ExtensionData.summary.TotalCPU)/1000
  $ClusterInfo.TotalMemGB="{0:n2}" -f ($cluster.ExtensionData.summary.TotalMemory/1GB)
  $ClusterInfo.CPUAvg = $cpuAverage.ToString()+'%'

  $ClusterInfo.MEMAvg = $memAverage.ToString()+'%'

 Start-UdDashboard -Content {
  New-UdDashboard -Title "Cluster Capacity Dashboard" -Color '#FF050F7F' -Content {
      New-UdGrid -Title "Cluster Capacity" -Endpoint{
     } -port 80 -AutoReload

Hey @vishnu,

Change your dashboard to load the data directly in the grid.

 Start-UdDashboard -Content {
  New-UdDashboard -Title "Cluster Capacity Dashboard" -Color '#FF050F7F' -Content {
      New-UdGrid -Title "Cluster Capacity" -Endpoint{
     } -port 80 -AutoReload

I tried and it says get-clustersummary is not recognized.

If you’re running UD 2.7, it should automatically find that function. If not, you’ll need to use New-UDEndpointInitialization to get that function defined in the PS runspace.


1 Like

Thanks Adam!
I updated to UD2.7 but still the function is not recognized.
It is giving me this error instead.

You have modified the global:DefaultVIServer and global:DefaultVIServers system variables. This is not allowed. Please reset them to $null and reconnect to the vSphere server.

The moment I modify the script back to old way it works.

Hi @vishnu when you upgraded, I take it you deleted/moved all previous files…there have been a few people on here just copy stuff over, and it doesn’t work properly, just want to rule that out.

Hi @psDevUK I removed the old module fully and installed new one… still the same issue

Can you look at this forum post? It provides some information on the error you are seeing: Work with VMware vCenter connections

I always use the -AutoRefresh followed by the -RefreshInterval 10 so that would refresh the grid every 10 seconds…Or change it to a value you want the grid to refresh on…

 New-UdGrid -Title "Cluster Capacity" -Endpoint{
      } -AutoRefresh -RefreshInterval 12

I tried this as well but still not working… it keeps on showing the same data until i re run the script…
I am thinking of creating schedule task to run this script every 10 mins until we get some solution.

I take it you ctrl+F5 your browser to make sure getting latest version? I’m sure on poshud.com there is grid example with reloading random numbers. Can you please verify that works ok for you? Thank you

I am getting the latest version. But the problem still persists.
This is due to the $obj get the data first and the same data shows up even after ctrl+f5 as the $obj was cached and displays the same value.


There is a solution for your issue which is by implementing $cache and $Schedule1 = New-UDEndpointSchedule -Every 10 -Minute

for example

$Task = New-UDEndpoint -Schedule $Schedule1 -Endpoint {
    $Cache:Task = ("what ever function or script you need to run every 10 minutes")
      Start-UDDashboard -Wait -Endpoint @($Task)......

this way your command will execute every 10 minutes and update the values

1 Like

Apologies I have been off work today and tried my best to keep away from the keyboard. Both methods mentioned would work…but I am assuming you would ‘call’ your function inside the endpoint as @adam described…then you can refresh that individual endpoint with the autorefresh and refreshinterval parameters…Or quite rightly as @wsl2001 has mentioned the sacred $Cache variable with a scheduled enpoint described here:-
Or as I was assuming import the function into UD then be able to call it from within any endpoint in your dashboard:-