Load Expansion Panel OnClick

Product: PowerShell Universal
Version: 2.1.2
Dashboard Framework: 3.5.0

Hi all,

I’m evaluating PowerShell Universal for work use. Good progress so far, but looking at optimizing load times on some pages. I have a section that’s showing recent AD object creation, but its slowing down the page quite a bit when it first loads. Is there a way to have the Expansion Panels process when expanded, instead of when the page loads? A combination of -Content and -OnClick or something?

Here’s the code I’m working with:

New-UDCard -Title 'Active Directory' -Content {
    New-UDExpansionPanelGroup -Children {
        New-UDExpansionPanel -Title 'Recent Users' -Content {
            $ADUserChangesColumns = @(
                New-UDTableColumn -Title 'Name' -Property 'Name'
                New-UDTableColumn -Title 'Title' -Property 'Title'
                New-UDTableColumn -Title 'Department' -Property 'Department'
                New-UDTableColumn -Title 'City' -Property 'City'
                New-UDTableColumn -Title 'whenCreated' -Property 'whenCreated'
                New-UDTableColumn -Title 'whenChanged' -Property 'whenChanged'
            )
            $ADUserChangesData = Get-ADUser -Filter * -Properties Title, Department, City, whenCreated, whenChanged | Select-Object -Property Name, Title, Department, City, whenCreated, whenChanged | Sort-Object -Property whenCreated, whenChanged -Descending | Select-Object -First 50

            New-UDTable -Columns $ADUserChangesColumns -Data $ADUserChangesData -Dense -PageSize 10 -ShowPagination
        }

        New-UDExpansionPanel -Title 'Recent Computers' -Content {
            $ADComputerChangesColumns = @(
                New-UDTableColumn -Title 'Name' -Property 'Name'
                New-UDTableColumn -Title 'OperatingSystem' -Property 'OperatingSystem'
                New-UDTableColumn -Title 'whenCreated' -Property 'whenCreated'
                New-UDTableColumn -Title 'whenChanged' -Property 'whenChanged'
            )
            $ADComputerChangesData = Get-ADComputer -Filter * -Properties OperatingSystem, whenCreated, whenChanged | Select-Object -Property Name, OperatingSystem, whenCreated, whenChanged | Sort-Object -Property whenCreated, whenChanged -Descending | Select-Object -First 50

            New-UDTable -Columns $ADComputerChangesColumns -Data $ADComputerChangesData -Dense -PageSize 10 -ShowPagination
        }

        New-UDExpansionPanel -Title 'Recent Objects' -Content {
            $ADObjectChangesColumns = @(
                New-UDTableColumn -Title 'DistinguishedName' -Property 'DistinguishedName'
                New-UDTableColumn -Title 'ObjectClass' -Property 'ObjectClass'
                New-UDTableColumn -Title 'whenCreated' -Property 'whenCreated'
                New-UDTableColumn -Title 'whenChanged' -Property 'whenChanged'
            )
            $ADObjectChangesData = Get-ADObject -Filter { ObjectClass -ne 'computer' -and ObjectClass -ne 'user' } -Properties Name, whenCreated, whenChanged | Select-Object -Property DistinguishedName, ObjectClass, whenCreated, whenChanged | Sort-Object -Property whenCreated, whenChanged -Descending | Select-Object -First 50

            New-UDTable -Columns $ADObjectChangesColumns -Data $ADObjectChangesData -Dense -PageSize 10 -ShowPagination
        }
    }
}

Thanks!

Hi and welcome,

when using

Get-ADUser -Filter *

the active directory will deliver you ALL user objects regardless of the creation date.
But you are only interested in the latest objects.
One of the golden powershell rules is: filter first.

#original code
Measure-Command{
    Get-ADUser -Filter * -Properties Title, Department, City, whenCreated, whenChanged | 
    Select-Object -Property Name, Title, Department, City, whenCreated, whenChanged | 
    Sort-Object -Property whenCreated, whenChanged -Descending | 
    Select-Object -First 50
} #TotalSeconds      : 18,0125691

#filtered for users created in the last 30 days
Measure-Command{
    $date = (Get-Date).AddDays(-30)
    Get-ADUser -Filter {whenCreated -gt $date} -Properties Title, Department, City, whenCreated, whenChanged | 
    Select-Object -Property Name, Title, Department, City, whenCreated, whenChanged | 
    Sort-Object -Property whenCreated, whenChanged -Descending | 
    Select-Object -First 50
} #TotalSeconds      : 1,0467177

There is a more faster option: Scheduled Endpoints - PowerShell Universal

You can load all AD objects for example every 5 min and save it to a $Cache Variable. On your page you access that variable and not the AD directly

1 Like

Oh shoot, I should have thought of that first: filter left, sort right. The AD Users and Computers wasn’t too big a hit, but I overlooked the enormity of getting all the AD Objects. Filtered it down to the past 30 days and getting much better performance now. I haven’t checked out Scheduled Endpoints yet, but that sounds perfect for a dynamic form I’m working on.

Thanks for all your help!