I am trying to connect with office365 PowerShell. I had also imported the module "ExchangeOnlineManagement". I'm getting the below exception:
"The term Connect-ExchangeOnline is not recognized as cmdlet, function , script or operable problem".
string script = @"
Set-ExecutionPolicy Unrestricted
$user = '<your username>'
$pwd = '<your password>'
$SecurePass = ConvertTo-SecureString -AsPlainText $pwd -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $user,$SecurePass
Import-Module -Name ExchangeOnlineManagement
Connect-ExchangeOnline -Credential $Cred
";
try
{
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
Pipeline pipe = runspace.CreatePipeline();
pipe.Commands.AddScript(script);
try
{
var results = pipe.Invoke();
}
catch (Exception e)
{
}
var error = pipe.Error.ReadToEnd();
if (error.Count > 0)
{
foreach (PSObject err in error)
{
//more logging not sharing that code
}
}
}
}
catch (Exception ex)
{ }