Running PowerShell cmdlets in C#


I need to run powershell cmdlets using C# in Visual Studio Console.

When I run the code an Exception occurs:

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.

Even though it works when I run the commands in Powershell.


Try to use PowerShell instance, like this:


Running PowerShell cmdlets in C# by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply