none
system center 2012sp1 的使用 RRS feed

  • 常规讨论

  • 我做了一个关于云服务的项目,本来用system center 2012 ,微软官方提供了sdk,但是现在用system center 2012sp1后没有sdk,自己写了服务,在程序中跑起来调用powershell,添加,停止,开启虚拟机都可以用,但是发布到iis上就是不可以使用,我想知道什么原因,下面是提示的错误。

    <?xml version="1.0" encoding="UTF-8"?> <string xmlns无法将“Stop-SCVirtualMachine”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。</string>


    我调用powershell的代码如下:

     

    public bool RunScript(List<string> scripts, List<PSParam> pars)         {

                try             {                 //新加的                 RunspaceConfiguration rconfig = RunspaceConfiguration.Create();                 PSSnapInException Pwarn = new PSSnapInException();                 string test = "Import-Module VirtualMachineManager\r\n";

                    Runspace runspace = RunspaceFactory.CreateRunspace();

                    runspace = RunspaceFactory.CreateRunspace(rconfig);//1

                    runspace.Open();

                    Pipeline pipeline = runspace.CreatePipeline();                 pipeline.Commands.AddScript(test);//1                 foreach (var scr in scripts)                 {                     pipeline.Commands.AddScript(scr);                 }

                    //注入参数                 if (pars != null)                 {                     foreach (var par in pars)                     {                         runspace.SessionStateProxy.SetVariable(par.Key, par.Value);                     }                 }

                    //返回结果                 Collection<PSObject> results = pipeline.Invoke();                 runspace.Close();                 return (results != null && results.Count > 0);

                }             catch (Exception)             {

                    return false;             }         }

     

    2013年9月4日 5:53