Ejemplo n.º 1
0
        public static Collection <SMA.PSObject> Invoke(string script, Dictionary <string, object> scriptParams, out SMA.PSDataStreams streams)
        {
            Collection <SMA.PSObject> psOutput;

            using (SMA.PowerShell psInstance = SMA.PowerShell.Create())
            {
                psInstance.AddScript(script);
                if (scriptParams != null)
                {
                    foreach (string paramName in scriptParams.Keys)
                    {
                        psInstance.AddParameter(paramName, scriptParams[paramName]);
                    }
                }

                psOutput = psInstance.Invoke();
                streams  = psInstance.Streams;
            }

            return(psOutput);
        }
Ejemplo n.º 2
0
		private static Exception GetStreamException(string cmdletName, PSDataStreams streams)
		{
			string str;
			string empty;
			if (streams.Error.Count <= 0)
			{
				return null;
			}
			else
			{
				PSDataCollection<ErrorRecord> error = streams.Error;
				string str1 = error[0].ToString();
				if (error.Count >= 2)
				{
					str = error[1].ToString();
				}
				else
				{
					str = string.Empty;
				}
				string str2 = str;
				if (error.Count >= 3)
				{
					empty = error[2].ToString();
				}
				else
				{
					empty = string.Empty;
				}
				string str3 = empty;
				Tracer tracer = new Tracer();
				tracer.CommandInvocationError(cmdletName, (uint)error.Count, str1, str2, str3);
				return error[0].Exception;
			}
		}
Ejemplo n.º 3
0
 private PowerShell()
 {
     psCommand = new PSCommand();
     dataStreams = new PSDataStreams(this);
 }
        string LogStreams(PSDataStreams streams)
        {
            List<String> entries = new List<string>();

            foreach (DebugRecord record in streams.Debug)
                entries.Add(String.Format("Debug: {0}", record));

            foreach (ErrorRecord record in streams.Error)
                entries.Add(String.Format("Error: {0}", record));

            foreach (VerboseRecord record in streams.Verbose)
                entries.Add(String.Format("Verbose: {0}", record));

            foreach (WarningRecord record in streams.Warning)
                entries.Add(String.Format("Warning: {0}", record));

            StringBuilder notes = new StringBuilder();

            foreach (string entry in entries)
                notes.AppendLine(entry);

            return notes.ToString();
        }
Ejemplo n.º 5
0
 private void UnhookStreamEvents(PSDataStreams streams)
 {
     streams.Warning.DataAdded -= WarningOnDataAdded;
     streams.Verbose.DataAdded -= VerboseOnDataAdded;
     streams.Information.DataAdded -= InformationOnDataAdded;
     streams.Progress.DataAdded -= ProgressOnDataAdded;
     streams.Error.DataAdded -= ErrorOnDataAdded;
     streams.Debug.DataAdded -= DebugOnDataAdded;
 }