Couldn't you just start a new PowerShell process and then pass the Install-Module as an argument?
How to install PowerShell module from .NET application
Hi
I need to install a PowerShell module from my .NET application. I have added Microsoft.PowerShell.SDK nuget package to the project and use PowerShell class to execute Install-Module cmdlet. Unfortunatly the execution failed with the following error:
No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
As I understood, Microsoft.PowerShell.SDK includes neither PackageManagement nor PowerShellGet module which are required for Install-Module cmdlet.
I'v also tries to install nuget package provider via Install-PackageProvider cmdlet. It failed with the following exception
Unhandled Exception - Message:'The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' threw an exception.' Name:'TypeInitializationException' Stack Trace:'
Any idias what I do wrong?