Best option for loading modules and variables for all pages of a dashboard running under Powershell Universal

What is the best and most flexible way to load modules and variables available to all pages of a dashboard running under Powershell Universal? Previously this was done with New-UDEndpointInitialization , the documentation simply saids “This cmdlet has been removed from Universal Dashboard. There is no longer a need to call it.” I have a pretty signification dashboard with multiple pages and I use modules to provide cleaner page code and to make debugging simple. Do I have to load the modules on each page or is there some way to load these at startup of the dashboard? If anyone could explain this, or point me to some documentation or examples I may have missed that would be most helpful.

image

That is how i load my custom functions file. I just have that in my dashboard.ps1 and it works just fine. As near as i can tell, you don’t have to add them in anymore.

I do mine slightly differently than Jacob, but only from an organizational standpoint.

I manage my functions in individual ps1 files for easier organization, upgrades and management. I toss them into a sub-folder called Functions, then use this code on my dashboard.ps1 for the UD page in question.

$functions = @()
Get-ChildItem (Join-Path $PSScriptRoot "Functions") | ForEach-Object -Process {
    . $_.FullName
    $functions += $_.name.replace('.ps1','')
}

Depending on the variables, I store data in a json formatted file and pull it all into a $Cache:configdata variable in this same location. Makes it easy to keep it abstracted from the pages and simple to update. I also do it this way so I can gitignore the json config for github uploads and such, and leave the sensitive config data as local only.

Modules, I tend to just make sure they are in the appropriate spot to auto-import for PowerShell sessions.

1 Like