I´m currently trying to call an powershell application from my asp core application.
My first command is Import-Module to make sure that the correct module is loaded.
I tried several ways to do this:
using (PowerShell ps = PowerShell.Create())
{
ps.AddCommand("Import-Module AzureRm").Invoke();
}
This throws an CommandNotFoundException:
CommandNotFoundException
The term 'Import-Module AzureRm' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path
is correct and try again.
If I use AddScript instead I don´t get any feedback at all:
var result = ps.AddScript("Import-Module AzureRm").Invoke();
Result is always returned as an empty object.
Is is even possible to use Import-Module in an ASP core application?
How do I get an result from AddScript and not an empty object?