Create Distribution group in Outlook using Microsoft Exchange Online with .Net

97 Views Asked by At

I am trying to create a distribution group in Outlook with the help of powershell module ExchangeOnlineManagement I was able to write out the script and it was working fine but When I try to create the same script using .Net and it is giving error

````
        using(PowerShell ps = PowerShell.Create(runspace)){
        SecureString credential = GetPassword();
        ps.AddCommand("Import-Module").AddParameter("Name", "ExchangeOnlineManagement");
        ps.Invoke();
        ps.Commands.Clear();
        ps.AddCommand("Connect-ExchangeOnline");
        ps.AddParameter("Credential", credential);
        Collection<PSObject> results = ps.Invoke();
        }
```

I am getting the following error

Unhandled exception. System.Management.Automation.CommandNotFoundException: The term 'Connect-ExchangeOnline' is not recognized as the name of a cmdlet, function, script file, or operable program.

Can anyone help me with this ?

0

There are 0 best solutions below