예제 #1
0
 private string Result(bool success)
 {
     return(string.Concat(
                LogFormatter.GetResultCode(success),
                Environment.NewLine,
                _logBuilder.ToString()));
 }
        public static bool Execute(this PowerShell instance, out string result)
        {
            Guard.IsNotNull(instance, nameof(instance));

            var results = instance.Invoke();
            Collection <ErrorRecord> errors = instance.Streams.Error.ReadAll();

            var sb = new StringBuilder();

            sb.AppendLine("Execution complete. Results: ");
            bool success = errors.Count == 0;

            sb.AppendLine(LogFormatter.GetResultCode(success));

            if (results != null)
            {
                foreach (PSObject item in results)
                {
                    sb.AppendLine(item.ToString());
                }
            }

            if (!success)
            {
                foreach (ErrorRecord error in errors)
                {
                    sb.AppendLine(error.ToString());
                }
            }

            result = sb.ToString();
            return(success);
        }