Running the poweshell command start-cachecluster programmatically fails

Bloqueada Running the poweshell command start-cachecluster programmatically fails

  • 11 octombrie 2010 14:31
     
     

    Tryig to run start-cachecluster programatically (http://blogs.msdn.com/b/skaufman/archive/2010/03/31/calling-powershell-from-net.aspx) . It fails with CommandNotFoundException any spontaneous idea what could be the reason. 

    var state = InitialSessionState.CreateDefault();

        state.ImportPSModule(new string[] { "DistributedCacheAdministration", "DistributedCacheConfiguration" });

    var rs = RunspaceFactory.CreateRunspace(state);

        rs.Open();

    var pipe = rs.CreatePipeline();

        pipe.Commands.Add(new Command("Start-CacheCluster"));

    var output = pipe.Invoke();  //CommandNotFoundException

     

Toate mesajele

  • 13 octombrie 2010 11:58
     
     Răspuns propus Are cod

    Hello. I tested this out today, and I couldn't reproduce your exception, but I do have a few ideas.

    First, in order to run PowerShell caching commands, you have to run Use-CacheCluster first. It sets the context for subsequent commands, so add the following line before the Start-CacheCluster line:

    pipe.Commands.Add(new Command("Use-CacheCluster"));
    

    This assumes that you are running the code on the cache host. Otherwise, you'd also have to provide parameters for -ConnectionString and -Provider.

    Next, the commands that actually modify the running state of the service need to be run as Administrator. I got a different exception (timeout) when I tried to call "Stop-CacheCluster" in my test. Only when I launched Visual Studio 2010 as an administrator did the command succeed.

    Also, on a 64-bit machine, which mine was, I had to change the Build | Configuration Manager settings to target x64. When the application was targeting x86, I got a different exception attempting to open the RunspaceFactory: "One or more errors occurred processing the module 'DistributedCacheAdministration' specified in the InitialSessionState object used to create this runspace. See the ErrorRecords property for a complete list of errors. The first error was: The specified module 'DistributedCacheAdministration' was not loaded because no valid module file was found in any module directory." Once I change the solution architecture to target x64, this went away. I imagine on an x86 machine, this is never an issue.

    I think the most likely fix for your problem is preceding all commands in your pipeline with a single call to "Use-CacheCluster". But I included the rest of my findings in case they help you or others.

    Jason Roth

  • 1 aprilie 2012 05:05
     
     

    hi,JasonRoth

    I  meet this problem also. i need to run PowerShell caching commands in wf application, i host wf into appfabric host. and i build the wf project to x64. then i deploy a website to visit the wf service. unsuccessful, and the error message is "Error: One or more errors occurred processing the module 'DistributedCacheAdministration' specified in the InitialSessionState object used to create this runspace. See the ErrorRecords property for a complete list of errors. The first error was: The specified module 'DistributedCacheAdministration' was not loaded because no valid module file was found in any module directory." but ,if i host it in a console application, it will run fine. so, i don't know if we need to do some configuration in iis when we host a workflow in it . do you know what's wrong with it ? i hope you can reply me ,if it is possible,when you feel free. thanks.  BTW: my english language is poor, i hope you can understand my mean.

  • 2 aprilie 2012 18:04
    Moderator
     
     

    I have worked with Runspaces quite a bit and I recommend trying to run the Powershell script from a prompt first, this will help a lot. I find it difficult to debug a runspace script from within the runspace itself, it is not very interactive.

    Do you already have the DistributedCacheAdministration module on your system you are trying to invoke this from? Running your script from a Powershell prompt should give you more diagnostic information too.

    Thanks,


    If this answers your question, please use the "Answer" button to say so | Ben Cline

  • 5 aprilie 2012 02:25
     
     

    hi, Ben Cline1

    I have the DistributedCacheAdministration module on my system, it in "C:\Program Files\AppFabric 1.1 for Windows Server\PowershellModules" directory.  I can run all caching commands in Powershell prompt.  if i host my WF service in a console application, it is ok . but if i host the service into IIS the error is happen. so i think maybe i need to do more configuration for the iis, but i don't know what i need to do.