I am trying to execute the command let in C# by creating a runspace pool and executing
here command New-ExoPSSession fails with error
using (PowerShell powershell = PowerShell.Create())
{
powershell.RunspacePool = ExchangeOnlineRunspacePool.Instance.RunspacePool;
powershell.Commands.AddCommand(command);
try
{
if (powershell.RunspacePool.RunspacePoolStateInfo.State == RunspacePoolState.Opened)
{
results = powershell.Invoke();
}
Command command = new Command("Import-Module");
command.Parameters.Add(new CommandParameter("name",moduleFullPath));
//ExchangeManagement.ExecuteCommand(null, ExchangeVersion.Exchange_Online, command, null, true);
ExecuteCommand(command);
======================================================
command = new Command("New-ExoPSSession");
command.Parameters.Add(new CommandParameter("ConnectionUri", ConnectionUri));
command.Parameters.Add(new CommandParameter("AzureADAuthorizationEndpointUri", AzureADAuthorizationEndpointUri));
command.Parameters.Add(new CommandParameter("Credential", PowershellCommonUtilities.GetPSCredential(connectInfo.UserName, connectInfo.Password)));
ExecuteCommand(command);
}