本文介绍了以编程方式运行poweshell命令start-cachecluster失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 以编程方式运行start-cachecluster( http://blogs.msdn.com/b/skaufman/存档/ 2010/04/31 /主叫的powershell从 - net.aspx)功能;.它失败了 CommandNotFoundException 任何自发的想法可能是什么原因。  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 命令( " Start-CacheCluster" )); var output = pipe.Invoke();  // CommandNotFoundException   解决方案 您好。我今天测试了这个,我无法重现你的异常,但我确实有一些想法。 首先,为了运行PowerShell缓存命令,你必须运行Use- CacheCluster首先。它为后续命令设置上下文,因此在Start-CacheCluster行之前添加以下行: pipe.Commands.Add( new 命令(" Use-CacheCluster" )); Tryig to run start-cachecluster programatically (http://blogs.msdn.com/b/skaufman/archive/2010/03/31/calling-powershell-from-net.aspx) . It fails withCommandNotFoundException any spontaneous idea what could be the reason. var state =InitialSessionState.CreateDefault();    state.ImportPSModule(newstring[] { "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  解决方案 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")); 这篇关于以编程方式运行poweshell命令start-cachecluster失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-24 12:14