Question

Can someone, please, help to understand why the following code inside a Csharp function

    Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();
    Pipeline pipe = runspace.CreatePipeline();
    Command connectToActDir = new Command("connect-QADService");
    connectToActDir.Parameters.Add("Service", "'ip:port'");
    connectToActDir.Parameters.Add("ConnectionAccount", "'user.local\administrator'");
    connectToActDir.Parameters.Add("ConnectionPassword", "'password'");
    pipe.Commands.Add(connectToActDir);
    pipe.Invoke();

causes the following error

The term 'connect-QADService' 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.

while ActiveRoles cmdlets are installed and running the equivalent command in power shell succeeds. Do I miss some dll in project references? Thanks

Was it helpful?

Solution

The Quest ActiveRoles cmdlets are not loaded into a PowerShell session by default, because they're not part of PowerShell.

PowerShell 3 will automatically load modules when needed. I don't know if this holds true when using a RunSpace as I've never used PowerShell this way.

Do you load the Quest snap-in or module in your PowerShell profile? You'll need to do the equivalent in your C# code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top