As the question is quite intuitive, I'm trying to use AzureRM in my asp .net core web application. I've created InitialStateSession and Runspace as follows.
Runsapce Version: 7.0.3
Installed the AzureRM module from powershellGallary.
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Bypass;
iss.ImportPSModule("AzureRM");
Runspace rso = RunspaceFactory.CreateRunspace(iss);
rso.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = rso;
ps.AddScript("Connect-AzureRmAccount");
var res = ps.Invoke();
var errors = ps.Streams.Error.ReadAll();
rso.Close();
when I run the code I get the following error
{The term 'Connect-AzureRmAccount' 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.}
While using the same commands directly on PowerShell works like charm. but it doesn't with c# code.
I even tried Importing the module like below.
iss.ImportPSModule("path to the module.psm1 or .psd1");
and
ps.AddScript("Import-Module azureRM");
ps.AddScript("Import-Module azureRM.Profile");
I've checked for the paths it is looking for the module and it included the modules path using this.
var path = rso.SessionStateProxy.GetVariable("env:PSModulePath");
I've installed azureRM.Netcore
also as there was some issue with versions.
Each tries to fix this is highly appreciated. thanks in advance.