Home:ALL Converter>Import-Module with powershell from asp core website

Import-Module with powershell from asp core website

Ask Time:2019-01-24T23:58:25         Author:Anne Radke

Json Formatter

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?

Author:Anne Radke,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/54350684/import-module-with-powershell-from-asp-core-website
yy