Running Powershell from .Net Core - Could not load file or assembly Microsoft.Management.Infrastructure

I had same issue, Microsoft.Management.Infrastructure.dll (and associated files) did not get published. Solved by specifying a non-portable RID in publish profile (*.pubxml, not the *.csproj):


Problem is probably caused by the fact, that under C:\Users\UserName\.nuget\packages\\1.0.0\runtimes there are only folders with non-portable RIDs; there is no win-x86 and win-x64.

Check application identity pool for Web app in pool. It may be rights issue Use identity impersonation or run on admin account. when you run from console you run with your identity when you run with app its app identity pool