Calling PS scripts with PS remoting from ASP.NET Core 6 Web App issue

Bojan Zivkovic 526 Reputation points
2025-02-19T14:29:46.74+00:00

Hi, I am evaluating ASP.NET Core 6 Web App (front end for PowerShell scripts). When PS script does not contain Invoke-Command/New-PSSession, Web App does the job, but, with either Invoke-Command or New-PSSession inside PS script I always get very generic error which has been torturing me for so long.

An error has occurred which PowerShell cannot handle. A remote session might have ended. [DCFQDN] An error has occurred which PowerShell cannot handle. A remote session might have ended.

App Pool is running under account having required permissions to remote to DC (everything works fine outside Web App). Other Web App has no problems with scripts containing PS remoting and also when I call PS script with PS remoting directly from IIS default.aspx it works well so I doubt IIS is playing any role here.

Any help would be highly appreciated.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,788 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,629 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 35,596 Reputation points
    2025-02-19T23:11:11.4066667+00:00

    Please refer to the original question.

    https://learn.microsoft.com/en-us/answers/questions/2117094/issues-with-web-front-end-app-for-background-ps-sc

    At this point my conclusion is that the problem exists somewhere within .Net Core or in this unnamed 3rd party web app. From my testing, "normal IIS/.Net" works fine. I am not familiar enough with .Net Core to be able to recreate this problem. I also don't know how this 3rd party app calls Powershell. I would assume that it is shelling out Powershell.exe, but for all I know it could be doing something else, like calling some flavor of pwsh.exe. (To align with the cross platform nature of .Net Core.)

    Bojan, I'm sorry, but it is virtually impossible for forum users to troubleshoot based on "An error has occurred which PowerShell cannot handle". We would need to know what that error is.

    Since you are using a 3rd party app, I would suggest that you work with their tech support team to troubleshoot the problem. Have them enable whatever troubleshooting tools that are available to them to trace the Powershell call. If nothing else, ask them how they implemented calling Powershell.

    Share with them the ASPX page that I wrote for you and ask them why that page works, but their application fails.


  2. Bojan Zivkovic 526 Reputation points
    2025-02-20T10:56:14.6633333+00:00

    Well, I cracked it. I found setting I brought up in discussion with vendor a few months ago - changed it to true.

    User's image

    As I thought, no double-hop, no IIS, no GPO ... Being stubborn paid off eventually. Problem is, this is not recommended from security perspective. On the other hand, I can hardly do anything do make app use other serialization methods - it should be done by app vendor.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.