PSCommand commandToRun = new PSCommand();
commandToRun.AddCommand("Connect-MsolService");
commandToRun.AddParameter("Credential", new PSCredential(msolUsername, msolPassword));
powershell.Streams.ClearStreams();
powershell.Commands = commandToRun;
powershell.Invoke();
I am trying to run above code in visual studio and getting the following error : The term 'Connect-MsolService' 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. But I am able to Connect to Msol service from Microsoft Azure Active Directory Module for Windows PowerShell. Please help.
Import-Module MSOnline
– Martin Brandl