public override Process CreateProcess(List <string> procParams, IList <IXenObject> targets)
        {
            Registry.AssertPowerShellInstalled();
            Registry.AssertPowerShellExecutionPolicyNonRestricted();

            string command = MakeInvocationExpression(Filename, Function, procParams, Params, targets, Debug);

            //escape the entire command statement as it is being passed into the -Command parameter in quotes
            command = EscapeQuotes(EscapeBackSlashes(command));

            return(new Process
            {
                StartInfo =
                {
                    FileName        = PluginDescriptor.PowerShellExecutable,
                    Arguments       = $"-NoLogo -Command \"Import-Module XenServerPSModule; {command}\"",
                    UseShellExecute = false,
                    CreateNoWindow  = !Window,
                    WindowStyle     = Window ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden
                }
            });
        }
Exemple #2
0
        public override Process CreateProcess(List <string> procParams, IList <IXenObject> targets)
        {
            Registry.AssertPowerShellInstalled();

            // get ourselves in the correct directory
            // put the parameters in the objInfoArray variable
            // exectute the plugin, with debugging if required
            string command = string.Format(
                "& {{ {0} }}",
                XenServerPowershellCmd.MakeInvocationExpression(Filename, Function, procParams, Params, targets, Debug));

            // finally we escape the entire command statement again as it is being passed into the -Command parameter in quotes
            command = XenServerPowershellCmd.EscapeQuotes(XenServerPowershellCmd.EscapeBackSlashes(command));

            Process proc = new Process();

            proc.StartInfo.FileName        = PluginDescriptor.PowerShellExecutable;
            proc.StartInfo.Arguments       = string.Format("-NoLogo -Command \"{0}\" {1}", command, string.Join(" ", new List <string>(Params).ToArray()));
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow  = !Window;
            proc.StartInfo.WindowStyle     = !Window ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Normal;
            return(proc);
        }