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 += $objComputer.name
}
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 "$Server.domain.com" -ErrorAction SilentlyContinue -filter "DriveType= 3" #-Credential $cred
$GridData = @{}
$DrveGrid = foreach ($objdisk in $Disks){
$total="{0:N0}" -f ($objDisk.Size/1GB)
$free=($objDisk.FreeSpace/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!