예제 #1
0
        /// <summary>
        ///		Ejecuta un script de powershell
        /// </summary>
        private async Task ExecuteContentAsync(BlockLogModel block, string content, NormalizedDictionary <object> parameters, ExecuteScriptSentence sentence)
        {
            PowerShellManager manager = new PowerShellManager();

            // Carga el script en memoria
            manager.LoadScript(content);
            // Asigna los parámetros
            if (!AddParameters(manager, parameters, sentence, out string error))
            {
                Errors.Add(error);
            }
            else
            {
                // Ejecuta
                await manager.ExecuteAsync();

                // Comprueba los errores
                if (manager.Errors.Count > 0)
                {
                    Errors.AddRange(manager.Errors);
                }
                else if (manager.OutputItems.Count > 0)
                {
                    foreach (object output in manager.OutputItems)
                    {
                        block.Info($"{manager.OutputItems.IndexOf(output).ToString()}: {output?.ToString()}");
                    }
                }
            }
        }