public static string GetScriptArgsTpl(ScriptDto scriptDto) { StringBuilder str = new StringBuilder("-ExecutionPolicy RemoteSigned "); PowershellParams p = scriptDto.PowershellParams; str.AppendFormat("{0}", p.NoProfile ? "-NoProfile " : ""); str.AppendFormat("{0}", p.NoExit ? "-NoExit " : ""); str.AppendFormat("{0}", p.NoLogo ? "-NoLogo " : ""); str.AppendFormat("{0}", p.WindowStyle != null ? "-WindowStyle " + p.WindowStyle + " " : ""); str.AppendFormat("-File \"{0}\" {1}", scriptDto.Path, scriptDto.Args); return(str.ToString()); }
internal List <ScriptDto> GetListScripts() { List <ScriptDto> retList = new List <ScriptDto>(); XmlNodeList list = XmlUtils.GetElementsXpath(xmlFile.Root, ".//script"); foreach (XmlElement xmlElement in list) { if (!xmlElement.HasAttribute("id")) { Console.WriteLine("Balise script detectée sans attribut id. Ignorée."); continue; } ScriptDto s = new ScriptDto() { Id = xmlElement.Attributes["id"].Value, Path = XmlUtils.GetElementXpath(xmlElement, "./path/text()")?.Value, Wd = XmlUtils.GetElementXpath(xmlElement, "./wd/text()")?.Value, Args = XmlUtils.GetElementXpath(xmlElement, "./args/text()")?.Value, }; if (retList.Any(r => r.Id.Equals(s.Id))) { Console.WriteLine("Balise script detectée sans attribut id. Ignorée."); continue; } XmlNode psParams = XmlUtils.GetElementXpath(xmlElement, "./powershellParams"); if (psParams != null) { XmlSerializer serializer = new XmlSerializer(typeof(PowershellParams)); PowershellParams p = null; using (XmlNodeReader reader = new XmlNodeReader(psParams)) { p = (PowershellParams)serializer.Deserialize(reader); } s.PowershellParams = p; } retList.Add(s); } return(retList); }