Dashboard not loading all page components during launch

This is about Project-Neith which I’m finally back to working on. I’m having an issue with my launcher script which seems to work properly except for one of the pages and I’m at a bit of a loss to fix.

There is a section of ./main.ps1 which loads all dependencies, determines which pages are active, dot-sources the script files, load pages to array, and then launch dashboard.

There’s a script file which I load (ad_pages.ps1) which doesn’t function properly. If I run ./ad_pages.ps1 and then run the ./main.ps1 it works fine.

In main.ps1 I have verified that it does run ad_pages.ps1. Here is the result:

There are two components not working properly.

  • A table does not load, it appears that the variable does not exist.
  • More concerning issue (since I’m planning to implement more things like it) is that the navigation buttons do not work, they don’t change the main content of the page. This is the green bar towards the top.

Here are the relevant bits of code.

  1. ./main.ps1 launches and it gets a list of files, it then does this:
Get-ChildItem -Path $pagedir -Filter *.ps1 -Recurse -Exclude dbconfig*,*sql_importer* | ForEach-Object {
    . $_.FullName
    write-host $_.fullname
    sleep -Seconds 2
}

The second line there SHOULD launch all scripts as if I went and ran ./somefile.ps1 however it doesn’t seem to completely work for ad_pages.ps1 because if I stop the dashboard, run ./ad_pages.ps1, and then run ./main.ps1 again, both of the above issues work properly.

  1. ad_pages.ps1 - Nav Buttons:
#Nav Menu for AD pages
$PageSelector = New-UDElement -Tag div -Attributes @{
    style = @{
        display = 'flex'; flexdirection = 'row';}
    } -Content { 
    New-UDButton -Text "AD Overview" -OnClick {
        Set-UDElement -Id page -Content { $ADSummary }
    }
    New-UDButton -Text "User Overview" -OnClick {
        Set-UDElement -Id page -Content { $UserOverview }
    }
    New-UDButton -Text "Computer Overview (Coming Soon!)" -OnClick {
        Set-UDElement -Id page -Content { $ComputersOverview }
    }
    New-UDButton -Text "??????? (Coming Soon!)"
}
  1. ad_pages.ps1 - AD Content for page which follows ( this is what loads the charts and buttons which are not working)
$ADSummary = New-UDLayout -Columns 1 -Content {
    #Summary of AD information
    New-UDLayout -Columns 4 -Content {
    #AD User Unlock
        New-UDInput -Title "Unlock User" -Endpoint {
            param($UserName)
            Unlock-ADAccount $UserName
            Sleep -Seconds 1
            $Res = Get-ADUser $Username -Properties LockedOut | Select-Object LockedOut
            If ($Res.LockedOut -eq $false) {
                New-UDInputAction -Toast "$UserName has been unlocked"
            }
            Else {
                New-UDInputAction -Toast "$UserName is still locked"
            }
        }
	#Enter Computer Name to view a dynamic page with core computer information
        New-UDInput -Title "Enter Computer Name: " -Endpoint {
            param($ComputerName)
            New-UDInputAction -RedirectUrl "/computer/main/$ComputerName"
        }
	#Enter a user name to view a dynamic page with core user information
        New-UDInput -Title "Enter User Name: " -Endpoint {
            param($UserName)
            New-UDInputAction -RedirectUrl "/user/$UserName"
        }
        New-UDInput -Title "Enter any AD Object: " -Endpoint {
            param($ObjectName)
            New-UDInputAction -RedirectUrl "/ad/$ObjectName"
        }
    }
    New-UDColumn -Size 12 {
        New-UDTable -Title "AD Data" -Headers @("total_users", "total_users_enabled", "total_computers", "total_enabled_computers", "total_groups", "forest_functional_level") -Endpoint {
            $ADData.GetEnumerator() | Out-UDTableData -Property @("total_users", "total_users_enabled", "total_computers", "total_enabled_computers", "total_groups", "forest_functional_level")
        }
        New-UDChart -Title "AD Features Over Time" -Height 600px -Width 100% -Type Line -Endpoint {
            $Features | Out-UDChartData -LabelProperty Date -Dataset @(
                New-UDChartDataset -DataProperty "Users" -Label "Users" -BackgroundColor "#80962F23" -HoverBackgroundColor "#80962F23"
                New-UDChartDataset -DataProperty "EnabledUsers" -Label "EnabledUsers" -BackgroundColor "#800FF22F" -HoverBackgroundColor "#800FF22F"
                New-UDChartDataset -DataProperty "Computers" -Label "Computers" -BackgroundColor "#8014558C" -HoverBackgroundColor "#8014558C"
                New-UDChartDataset -DataProperty "EnabledComputers" -Label "EnabledComputers" -BackgroundColor "#803AE8CE" -HoverBackgroundColor "#803AE8CE"
            )
        } 
    }
}
  1. ad_pages.ps1 - AD Page (the page where things aren’t working, the nav bar is loaded to this page which then calls a specific section of content.
$ADDataPage = New-UDPage -Name "ADSummary" -Icon signal -Content {
    $PageSelector
    New-UDRow
    New-UDElement -tag div -id page -Content {
        $ADSummary
    }
}