Still learning but getting there and need advice

So im still really new to this… but with hte couple of questions ive asked and by looking through the various posts on here and youtube videos, im creating a dashboard. And ive been pleased with it, its given me the information ive needed and even had a splash of color. My issue is the speed of it whcih i know comes down to my coding.

So far i have two tables, table one shows the top 5 servers for CPU%, table two shows the MemUtilization%.
Both color depending on the % (red, yellow, green)
refreshes every x seconds/minutes

Im having two issues:
if i use an array with manually typed in computer names it all works. The momemnt i change that array to be a “get-adcomputer” the dashboard dont work, even though the array contains the names?

My second issue is speed, im processing around 200 machines to get the above information, but it appears to be taking 4-6minutes to do? and im also doing this per table when i wonder if i should be using new-UDendpoint? and then simply taking the array from that endpoint inot the two tables grabbing CPU and memory respectively?

although ive used powershell for sometime, im still very green in all fairness, and i know i should be able to get this information far quicker, but im simply hitting a mental block and google blind allys so if anyone has advice and even stripped down examples id be so grateful

When you are dealing with multiple servers the best way to speed up the process is to leverage parallel process.

In UD you can use this plan to speed up things.
A- google invoke parallel and implement it in your code.
B- whenever you have a continuous process always add that to $Cache and to a schedule endpoint.
This way the scheduled endpoint will run every 5 min for example and cache your results so when you query your results from cache it will right there right away.

1 Like

So is invoke-parallel installed from PSgalley?

Of does using jobs do the same thing?

my idea is i want the table to update the relevant information, with a handful of servers it works bt anything more than that, it just sits there, im guessing because ive got the refreshinterval set to 60seconds and the actual information gathering is taking far longer so it has nothing to show

That’s when you get cache and schedule service endpoint in place.
The schedule service endpoint is like scheduled task it runs your command every x amount of time you defined.
And caching the results will help from having to wait for it to process every time you load your page

OK im stuck and stuck big time… i cant work out how to multithread the work?

new-udrow {
New-UDColumn -size 6 {
New-UDTable -Title “Top 5 Servers Processors” -Headers @(“Name”,“CPU%”,“LastCheck”) -AutoRefresh -RefreshInterval 60 -Endpoint {

  Foreach($server in $cache:servers) {
        #$timestamp = Get-Date -Format "dd/MM/yyyy HH:mm:ss"
        $proc = (Get-WmiObject win32_processor -computername $server | 
                    Measure-Object -property LoadPercentage -Average | 
                        Select-Object @{e={[math]::Round($_.Average,1)};n="CPU(%)"} -ErrorAction SilentlyContinue)
        $name = (get-wmiobject win32_computersystem).name
       $serverproc = [pscustomobject]@{

            Name = $server
            CPU = $proc."cpu(%)"
            Memory = ""
            Lastcheck = (Get-Date -Format "dd/MM/yyyy HH:mm:ss")
        $monitoredProc += $serverproc

       $monitoredProc|sort-object "CPU" -Descending|Select-Object "Name","CPU","Lastcheck" -first 5|ForEach-Object {

       $bgcolor = 'green'
       $fontcolor = 'white'

       if($_.cpu -ge '50'){
        $bgcolor = 'red'
        $fontcolor = 'white'

        Name = $
        CPU = New-UDElement -tag 'div' -Attributes @{style = @{'backgroundColor' = $bgcolor;color = $fontcolor}} -content {$_.cpu.tostring()}
        lastcheck = $_.lastcheck

} |Out-UDTabledata -Property @("Name","CPU","LastCheck")


$cache:servers contains my AD query to return the names of the computers i want to query


Try this blog, maybe there is a solution working for you.

Never had that need and dont know if there are limitations from UD using powershell jobs or something like that.

here is an example for you

$Cache:Webservers = $Servers | Invoke-Parallel -ImportFunctions -ScriptBlock {
        Get-IISSite -ComputerName $_
    } -RunspaceTimeout 2000 -Throttle 4 | ForEach-Object { 
        $Name = $_.Name
        $PhPath = $_.PhysicalPath -replace (":", "$")
        $Server = $_.ComputerName
        $AppPool = $_.AppPool