PowerShell Universal root module loading

PowerShell Universal root module loading

avatar

We are using a root module in PowerShell Universal. When I add the root module configuration to the `"Data": {}` section of `appsettings.json`, no errors occur, and the module appears to load correctly. Like this example: https://docs.devolutions.net/powershell-universal/platform/modules#example

However, when I reload all configurations through the GUI, the root module and all other modules no longer load. If I remove the root module setting from `appsettings.json`, everything works as expected again.

I would like to load the root module through `appsettings.json` because it seems that PowerShell Universal loads modules in alphabetical order.

For example, I have a module called `MODULE.Aa`, which uses a variable defined in my `MODULE.Root` module. Since `MODULE.Aa` appears to load before `MODULE.Root`, the variable is not available when `MODULE.Aa` runs, causing an error.

Is there a way to configure the root module so that it loads correctly and its variables are available to other modules, even after reloading all configurations through the GUI?

All Comments (6)

avatar

Hi Romano,

Thank you for the detailed report.

I reproduced this on a PowerShell Universal 2026.3.3 test server. With Data.Module set, the root module and the module it requires loaded at startup, their resources were gone after a configuration reload through the API, which runs the same code as Reload Configuration Files, and a restart of the service brought them back. In the versions I checked, from 2026.1.6 to 2026.3.3, the reload does not run the root module step, and while Data.Module is set it also skips your modules that have a .universal folder or the PowerShellUniversal tag. Our documentation also notes that a change to the root module setting needs a restart.

https://docs.devolutions.net/powershell-universal/platform/modules#root-module

What worked in my test, also after a reload, is to remove the root module setting and let MODULE.Aa read the value through a function instead of the variable.

1. In MODULE.Root.psm1, add a function that returns the value, and make sure MODULE.Root exports it and lists it in FunctionsToExport.

function Get-RootSetting { $RootSetting }

2. In MODULE.Aa, call Get-RootSetting where you now use the variable.

MODULE.Aa needs no RequiredModules for this, as long as MODULE.Root is on the module path. PowerShell then imports it on the first call. In my test it sat in the repository's Modules folder, which PowerShell Universal adds to that path.

The function worked both in a script and in an API endpoint from MODULE.Aa. Sharing the variable itself only worked partly. With RequiredModules in MODULE.Aa.psd1 and the variable exported from MODULE.Root, the script read the value but the endpoint saw it empty.

Please tell me where MODULE.Root is installed and which PowerShell Universal version you run. If the variable is defined or read somewhere else, for example under a .universal folder, also send me where and the failing line with its error, and I will check it.

Best regards,

Michel

Michel Audi

avatar

Hi Michel,

Thank you for your response. I am running PowerShell Universal 2026.3.3, and the modules are stored in the `Modules` folder within the PowerShell Universal repository.

You're right, but I meant something slightly different. Sorry for the unclear question.

In `MODULE.Root`, I create a PowerShell Universal variable using `New-PSUVariable` in `.universal/variables`, for example, `PSU_ENV`.

In `MODULE.Aa`, I create a PowerShell Universal role that uses this `PSU_ENV` variable in a switch statement to determine which AD group to use.

However, it seems that `MODULE.Aa` loads before `MODULE.Root`, meaning that the `PSU_ENV` variable is not yet available when `MODULE.Aa` is loaded. This happens when the root module is not set in the appsettings.json

My thought was to configure the root module in `appsettings.json`, as described in the documentation, to ensure that it loads before the other modules.

However, after configuring this setting, the modules no longer load when I reload all configurations through the GUI, as you reproduced. They only load correctly again after restarting the PowerShell Universal service.

I hope that makes things a bit clearer

avatar

Hi Romano,

Thank you for the clarification, that makes it clear.

I rebuilt your setup on a PowerShell Universal 2026.3.3 test server, without the root module setting. MODULE.Root creates PSU_ENV with New-PSUVariable in its .universal folder, and a role in MODULE.Aa picks its group from PSU_ENV in a switch. The role saw an empty PSU_ENV at startup, after a reload and after a restart. PowerShell Universal reads each module's .universal files with only the variables that are already loaded, and MODULE.Aa was read before MODULE.Root.

What worked in my test is to move the New-PSUVariable line for PSU_ENV out of MODULE.Root and into variables.ps1 in the repository's own .universal folder. PowerShell Universal reads that file before any module. The role then got PSU_ENV and the matching group at startup, after two reloads and after a restart.

I also tried RequiredModules = @('MODULE.Root') in MODULE.Aa.psd1. MODULE.Root was then read first at startup, but after a reload the role saw an empty PSU_ENV again until the next restart, so I would not rely on it.

The reloads in my test went through the API, which runs the same code as Reload Configuration Files. In my test the switch sat directly in roles.ps1 and set the role's claim value. If yours is inside the role's policy script block instead, please tell me and I will check that case too.

Best regards,

Michel

Michel Audi

avatar

Hi Michel,

Thank you again for your response. This is exactly the issue I am running into. My switch is also defined directly in roles.ps1, not in the role's policy script block.

I can move the variable definition to the PowerShell Universal repository's .universal folder, but I would have expected this to work with a root module as well. I see the benefits of using a root module, especially when combined with the other capabilities it offers.

Is this behavior by design, or would it be possible to improve or adjust the loading process to support this scenario?

Best regards,

Romano

avatar

Hi Romano,

Thank you for confirming your setup.

The reload behaviour is not by design. I sent my test results to our QA team, and they confirmed that a change already made in PowerShell Universal fixes the two reload problems from this thread. The first is your modules no longer loading after Reload Configuration Files while the root module setting is in appsettings.json. The second is MODULE.Aa seeing an empty PSU_ENV after a reload when MODULE.Aa.psd1 lists MODULE.Root in RequiredModules. That fix is not in 2026.3.3 and will be part of an upcoming PowerShell Universal release.

Until then, defining PSU_ENV in variables.ps1 in the repository's own .universal folder is the setup that held in my test at startup, after reloads and after a restart.

When the release with the fix is out, I will run your layout again on it, once with the root module setting and once with RequiredModules, and tell you which of them keeps PSU_ENV available to the role in MODULE.Aa. You can then decide whether to move the variable back into MODULE.Root.

Best regards,

Michel

Michel Audi

avatar

Hi Michel,

Thank you for your response. For now, I’ll indeed put the variable in variables.ps1 in the .universal folder of the PowerShell Universal repository.

I look forward to hearing from you when a new release containing this fix is available!

Thanks again for your help so far.

Best regards,

Romano