I used the "System.Management.Automation.dll" for executing PowerShell Commands from C# code. But I could not execute the Service Fabric Commands.
When I execute the Service Fabric commands i get the following error
The specified module 'ServiceFabric' was not loaded because no valid module file was found in any module directory
The term 'Connect-ServiceFabricCluster' 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.
The Code I used is
var shell = PowerShell.Create();
shell.Commands.AddScript("Import-Module ServiceFabric");
shell.Commands.AddScript("Connect-ServiceFabricCluster");
var result = shell.Invoke();
These Commands worked successfully when I executed them directly from the PowerShell command window.
The above code works fine for other PowerShell Commands
I also tried loading the Module using the physical path "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ServiceFabric" That didn't work either.