Numerous v5 Issues

Apologies for the lack of GitHub issues and reproducibility, but there is often little obvious reason as to the cause of these and I don’t have hours to spend collecting information on each issue, so I’m just posting it here.

Upgraded from v4 to 5.1.2 and having lots of issues.

Custom Environments for PowerShell 7 don’t seem to work at all, I’ve had to switch Apps and Scripts to use the Integrated environment, otherwise I get all sorts of strange exceptions such as:
MethodException: Cannot find an overload for "StartJob" and the argument count: "3". for jobs. The dashboards just don’t even seem to start at all.

Environment:

New-PSUEnvironment -Name "PowerShell 7" -Version "7.4.6" -Path "C:\Program Files\PowerShell\7\pwsh.exe" -Variables @('*') -MaxRunspaces 50 -Description "PowerShell 7" 

I’ve tried switching my dashboards to use the Integrated environment but I really need the custom environments feature to work because I’m getting type pollution between dashboards.

I can’t seem to reload/refresh pages in the Admin Console (e.g., /admin/apps) because it gives an Unauthorised error, sometimes it’ll even occur when I’m navigating around the sidebar menu in admin. I’m assuming this is due to some sort of CSRF protection? Either way, it makes the app even more difficult to use especially with how often the v5 admin console errors out.

The “Run Script” button seems to always fail for PSU Script Jobs with (Optional?) Parameters:

An error occured. Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at PowerShellUniversal.DefaultParameterValueService.SetDefaultValue(JobParameter jobParameter, ScriptParameter scriptParameter) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Automation\DefaultParameterValueService.cs:line 105
at PowerShellUniversal.ScriptParameters.FilterParameters() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Shared\Automation\ScriptParameters.razor:line 196
at PowerShellUniversal.ScriptParameters.OnParametersSetAsync() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Shared\Automation\ScriptParameters.razor:line 208
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

There also appears to be some issue with setting the Portal Roles from the Admin UI, I don’t think it saves it correctly to settings.ps1 or something.

Some more information on using custom Environments for Dashboards, the following test dashboard:

New-PSUApp -Name "Test" -FilePath "dashboards\Test\Test.ps1" -BaseUrl "/d/test" -Environment "PowerShell 7" -Authenticated -Role @('Administrator') -AutoDeploy -Description "Test dashboard with minimal functionality." 

defined as-

New-UDApp -Content { 'Hello, World!' }

Results in “Start failed” with the log:

[1/13/2025 4:51:21 PM] [Information] [App-Test] Dashboard configuration complete. 
[1/13/2025 4:51:21 PM] [Error] [App-Test] Inner Exception: System.IO.FileLoadException 
[1/13/2025 4:51:21 PM] [Error] [App-Test] Failed to get dashboard. Assembly with same name is already loaded System.Management.Automation.CmdletInvocationException 
[1/13/2025 4:51:20 PM] [Information] [App-Test] Creating services. 
[1/13/2025 4:51:20 PM] [Information] [App-Test] Dashboard information received. Starting dashboard. 
[1/13/2025 4:51:20 PM] [Information] [App-Test] Waiting for dashboard information... 

Do you have a different version of the Universal module installed in this environment that might be conflicting with PSU itself?

I ask because the StartJob exception and assembly issue sound like it’s mixing versions.

I just double checked in both my dev machine and test lab and can run custom environments with both 5.1.2 and 5.2.0.

New-PSUEnvironment -Name "Persistent" -Path "pwsh.exe" -PersistentRunspace 

I wonder if this is related to the authentication issues you are seeing. I also tried to reproduce this in 5.1.2 and 5.2.0 and it seems to be saving properly. It should look like this in settings.ps1.

I can reproduce an issue with this after I restart the server. Will be fixed in 5.2.

$Parameters = @{
	PortalRole = @('Operator')
}
Set-PSUSetting @Parameters

What type of authentication are you using?

Can you share your param block for this script?

Strangely enough, PowerShell 5.1 and 7+ (outside of PSU) report that Universal module isn’t even installed in CurrentUser (Of the PSU Service User) or AllUsers. I’m using the MSI install of PSU.

OpenID Connect with Azure/EntraID

Param(
    $ServiceNames = @()
)

Did you uninstall the previous version of PSU and install v5? It certainly seems like we have some mixing of assemblies or a failed install of some kind.

No, I installed the MSI over the top like I’ve always done. I see now in the docs that’s an unsupported scenario.

You may have two versions of PSU listed in Add\Remote programs. For major upgrades we recommend uninstalling the previous and installing the new one. I would verify that everything is uninstalled before installing the new version.

Removing PSU 4 appears to have resolved the custom environments problem, I’ve updated our change management process for PSU major version upgrades.

Might I recommend perhaps using a CustomAction in the MSI to warn the user if an older major version of PSU is detected? You might be able to get away with some of the native version checking stuff (depending on what you’re using to package your MSI) but that depends if you’re using the UpgradeCode GUID correctly but it also might not work if you need to support non-MSI installs, hence why a CustomAction might work better.

Microsoft.Graph Module works in Integrated environment and PowerShell 7 outside of PSU but doesn’t seem to work in my PowerShell 7 Custom Environment:

Could not load file or assembly 'Microsoft.Identity.Client, Version=4.61.3.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)

I removed all versions of all Microsoft.Graph, Microsoft.Graph.* modules and installed them fresh from PSGallery (2.25.0.0) to no avail.

I’ll take a look tomorrow. It looks like PSU ships with Microsoft.Identity.Client 4.65.0 so it should be fine but will have to see why it isn’t loading.

1 Like

I opened an issue for this as to not forget: Issue loading Microsoft Graph module · Issue #4225 · ironmansoftware/powershell-universal · GitHub

What’s your preferences regarding forum posts versus GitHub issues? I only try to submit GitHub issues for issues with a reproduction, which often requires understanding causation.
I try to avoid submitting GitHub Issues for problems which could just be environmental.

I feel like GitHub issues are good, even if it appears environmental. Having a curated list of work items is sometimes easier than the forums. Issues have a tendency to get buried much easier here.

I have this working in 5.2.1. It might be related to the Az issue that I resolved as well.

While Microsoft.Identity.Client was almost the newest version (now it will be latest) we had some out-dated Azure assemblies that might have been causing this.

1 Like

I updated to 5.2.1, unfortunately, it didn’t seem to resolve the Graph issue for me:

Could not load file or assembly 'Microsoft.Identity.Client, Version=4.67.2.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)

EDIT: Updating the Azure Modules resolved the issues.

1 Like

Should I create a GitHub issue for the “Run Script” issue?

Please. I would need a little more information on the param block used.