Help with data coming from remote server on scheduled endpoint

I am trying to run an endpoint on remote servers to bring back updates information.
I then put the contents of updates into a page with a table.

I can never get the table to fill with data.

Please help me figure this out. UD is such an awesome product.

Code below:

#. (Join-Path $PSScriptRoot "utils2.ps1")
function Cache-Updates {
    
    param (
        [String[]] $Servers
    )

    ForEach ($Server in $Servers) {

        $Cache:Updates += Invoke-Command -ComputerName $Server -Script {ipmo PSWindowsUpdate; Get-WUList -MicrosoftUpdate}
    }
    
    Write-UDLog -Message "---------------------------CACHED UPDATES $Server---------------------------"
    #Write-UDLog $AllUpdates
}

function New-UDServerPage {
    param(
        $Server
    )

    New-UDPage -Name $Server -Content {
        
        New-UDElement -Tag div -Attributes @{ style = @{ paddingLeft = "20px" }} -Endpoint {

            $Updates = $Cache:Updates | where { $_.ComputerName -eq "$Server" }
            $updatecount = $Updates.count

            New-UDTable -Title "Updates not installed for $Server. There are: $updatecount" -Headers @("Update Title", "KB", "Severity", "Size")  -Endpoint {
                
                $Updates | ForEach-Object {
                    [PSCustomObject]@{
                        title = $_.title
                        kb = $_.kb
                        severity = "None"
                        size = $_.size
                    }
                } | Out-UDTableData -Property @("title", "kb", "severity", "size")
            } -AutoRefresh -RefreshInterval 10
        }
    }
} # end of function

$Pages = @()
$Pages += . (Join-Path $PSScriptRoot "\home.ps1")

$serverNav = @()

$servers = @('SERVER01',
  'SERVER02',
  'SERVER03') 

$EI = New-UDEndpointInitialization -Function Cache-Updates

$Schedule30 = New-UDEndpointSchedule -Every 5 -Minute 
$EndpointUpdates = New-UDEndpoint -Endpoint {
    $Cache:Updates = Cache-Updates $servers
}

$servers | ForEach-Object {
  $page = New-UDServerPage -Server $_
  $serverNav += New-UDSideNavItem -Text $_ -Url $_
  $Pages += $Page
}

$Navigation = New-UDSideNav -Content {
    New-UDSideNavItem -Text "Home" -Url "Home" -Icon home
    $serverNav
} -Fixed

New-UDDashboard -Title "Outstanding Windows Updates for servers" -Pages $Pages -Navigation $Navigation -EndpointInitialization $EI

Hi @aloysmichaelsmith thanks for posting this question. Also thank you for posting some code example to go with it. So I have not solved this yet, but I see a few issues that maybe you need to be fixed first in order to solve the problem. So I see in the $EI variable you are only passing one of your two functions as a endpoint initialization, I would look at putting in both as an array. Next the $Schedule30 vairable is assigned but never used, and the same for $EndpointUpdates variable assigned but never used. Which is also calling a function from the top of the script.
You seem to keep calling $Cache:Updates which is not set, you set this in $EndpointUpdates which is not used. I think that is part of the problem. Correct what it mentioned and if still struggling please post back an update with the modified code. Thanks

Hi again @psDevUK and greetings @aloysmichaelsmith

See this part:
$EndpointUpdates = New-UDEndpoint -Endpoint {
$Cache:Updates = Cache-Updates $servers
}

Write the code as such, in order to not overwrite the $cache:updates:
$EndpointUpdates = New-UDEndpoint -Endpoint {
Cache-Updates $servers
}
Or have the function return the values, instead of directly adding them to the $cache:updates.

Rest of the code looks clean!

1 Like

thanks @psDevUK.
I cleaned up some of that and added the array to $EI

Hey @BoSen29,

Great help. I changed the function to use a variable and return that, then I populated $Cache:Updates in the endpoint. Seems to work now.

 $EndpointUpdates = New-UDEndpoint -Endpoint {
    $Cache:Updates = Cache-Updates $servers
} -Schedule $Schedule30
function Cache-Updates {
    
    param (
        [String[]] $Servers
    )

    ForEach ($Server in $Servers) {

        $ServerUpdates += Invoke-Command -ComputerName $Server -Script {ipmo PSWindowsUpdate; Get-WUList -MicrosoftUpdate}
    }
    
    Return $ServerUpdates
    
    Write-UDLog -Message "---------------------------CACHED UPDATES $Server---------------------------"
    #Write-UDLog $AllUpdates
}

Cheers.

2 Likes

@aloysmichaelsmith
Anytime bro!

Happy scripting