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

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):

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

Problem is probably caused by the fact, that under C:\Users\UserName\.nuget\packages\microsoft.management.infrastructure\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


You can load any DLL from Powershell, so one solution that should definitely work is loading the Microsoft.Management.Infrastructure DLL as part of the script. But before doing that, let's verify the difference between what's loaded in dev and prod powershell sessions.

You can get the list of currently loaded assemblies in PowerShell by running [Threading.Thread]::GetDomain().GetAssemblies(). Add this line at the start and end of your script (at the end because PowerShell will auto-load referenced assemblies if it can, when they are first used in the script). Now run the script on dev and prod and compare the results. Chances are, Microsoft.Management.Infrastructure will be missing on prod.

The assemblies list output shows the location of the assemblies. From the dev list, grab the Microsoft.Management.Infrastructure DLL file. You now have two options:

  1. Put the file in the prod machine's GAC. PowerShell should now load the DLL automatically as required.
  2. Make loading this DLL file part of your PowerShell script. Add [Reflection.Assembly]::LoadFile($fullPathToDLL) at the start of your script (or anywhere before you use Microsoft.Management.Infrastructure).