Trying to Build Utilization Monitoring Dashboard using UDSelect into a UDGrid

I’m bad with titles so I’ll explain more here…

I’m working on getting a Utilization Dashboard built that will provide a drop down select list of all of the servers within my domain.

What I would like to be able to do is select a Server from the list and then have some Metrics (Grids, Monitors) display on the page.

I’ve decided to tackle Disk Utilization first and I can’t seem to get the code right for building the New-UDGrid inside of the -OnChange switch for the UDSelect.

Here is a look at the code behind the page I’m building now. The Select Seems to work fine and I’m able to see a Toast Message when testing it. But all the other scriptblocks don’t seem to functioning.

New-UDPage -Name "Utilization Metrics Testing" -AuthorizedRole "Administrator" -Content {
  New-UDCard -Title "Pick a Server to Monitor" -Content {
    #$strCategory = "computer" 
    $strOperatingSystem = "Windows*Server*" 
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://DC=domain,DC=local,DC=com") 
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher 
    $objSearcher.SearchRoot = $objDomain 
    $objSearcher.Filter = ("OperatingSystem=$strOperatingSystem") 
    $colProplist = "name" 
    foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} 
    $colResults = $objSearcher.FindAll() 
    $ServerList = @() 
    foreach ($objResult in $colResults) 
        $objComputer = $objResult.Properties;  
        $ServerList += $ 
    New-UDSelect -Label "Server Select" -Option {
        foreach ($serv in $ServerList){
            New-UDSelectOption -Name "$serv" -Value "$serv"
    } -OnChange {
        #Show-UDToast -Message $EventData ##Testing
        $EventData = [string]$Server
        $Disks = Get-wmiobject  Win32_LogicalDisk -computername "$" -ErrorAction SilentlyContinue -filter "DriveType= 3" #-Credential $cred 
        $GridData = @{}
        $DrveGrid = foreach ($objdisk in $Disks){  
            $total="{0:N0}" -f ($objDisk.Size/1GB)  
            $freePercent="{0:P0}" -f ([double]$objDisk.FreeSpace/[double]$objDisk.Size)  
            $GridData += [PSCustomObject]@{Drive = $objDisk.Size; Total_Size_GB = $total; Free_Space_GB = $free; Free_Space_percent = $freePercent; volumename = $objdisk.VolumeName}

        New-UDGrid -Title "Disk Statistics for $Server" -Headers @("Drive", "Total size (GB)", "Free Space (GB)", "Free Space (%)","Name") -Properties @("Drive","Total_Size_GB","Free_Space_GB","Free_Space_percent","volumename") -Endpoint{
            @($GridData) | Out-UDGridData 
        } -AutoRefresh

Is this even possible to do? I feel like the code should work but I essentially get nothing back in logs or anything its almost as if the entire scriptblock doesn’t run. Any help would as always be great appreciated!

So, I’ve figured out that this works to build the Grid how I want.

$Disks = Get-wmiobject  Win32_LogicalDisk -computername "$" -filter "DriveType= 3" 
$GridData = @()
foreach ($objdisk in $Disks){   
    $total="{0:N0}" -f ($objDisk.Size/1GB)  
    $freePercent="{0:P0}" -f ([double]$objDisk.FreeSpace/[double]$objDisk.Size)  
    $GridObject = New-Object PSObject -Property @{Drive = $objDisk.DeviceID; Total_Size_GB = 
    $total; Free_Space_GB = $free; Free_Space_percent = $freePercent; volumename = $objdisk.VolumeName}
    $GridData += $GridObject
$Cache:Data = $GridData
New-UDGrid -Title "Disk Statistics for $Server" -Headers @("Drive", "Total size (GB)", "Free Space (GB)", "Free Space (%)","Name") -Properties @("Drive","Total_Size_GB","Free_Space_GB","Free_Space_percent","volumename") -Endpoint{
    @($Cache:Data) | Out-UDGridData 

This will build the disk utilization grid. But this exact code plugged into the -OnChange switch still doesn’t generate the Grid from the Server Selection.

Hi @aggiebeckett
Check out this:

The onChange endpoint doesn’t have anywhere to put the Grid, the usual way to solve this is to use New-UDInput and have New-UDInputAction to replace the form’s content with new content.

In the github example however, I’ve added a $Session variable with the name of “activeServer” and then sync the parent of the Grid.

Happy hunting!

1 Like

Had to Move a few Variables around to make it work on my end but overall that worked like a Charm. Thank you once again for the quick help @BoSen29!

On to health monitors now! I’m thinking with that New-UDElement solution you came up with here I can apply multiple views to one page per server. This should be really cool once I’m done I’ll make sure to share whatever I come up with back here.

1 Like

Awesome @aggiebeckett!

I usually use both this solution, with a form uptop to generate certain reports / graphs / grids, and Tabs on top, so i can have multiple tabs with dynamic data below.

Looking forward to see your solutions dude :slight_smile: