public static Command ToCommand(this IMsolCmdlet source) { if (source == null) { return((Command)null); } Command command = new Command(source.CommandText); PropertyInfo[] propertiesInfo = source.GetType().GetProperties(); foreach (PropertyInfo propertyInfo in propertiesInfo) { if (propertyInfo.IsDefined(typeof(DataMemberAttribute))) { var value = propertyInfo.GetValue(source); if (value != null) { var defaultObject = TypeExtension.GetNewObject(propertyInfo.PropertyType); if (!value.Equals(defaultObject)) { command.Parameters.Add(propertyInfo.Name, value); } } } } return(command); }
public ICollection <PSObject> PipelineInvoke(IMsolCmdlet command) { //Create Runspace if it has not already been created if (_runspace == null) { InitializeRunspace(); } //Create Pipeline and add teh command Pipeline pipeline = _runspace.CreatePipeline(); pipeline.Commands.Add(MsolCmdletExtensions.ToCommand(command)); //Invoke the command and return the results return(pipeline.Invoke()); }
public ICollection <PSObject> PipelineInvoke(IMsolCmdlet command, out PipelineReader <object> Errors) { //Create Runspace if it has not already been created if (_runspace == null) { InitializeRunspace(); } //Create Pipeline and add the command Pipeline pipeline = _runspace.CreatePipeline(); pipeline.Commands.Add(MsolCmdletExtensions.ToCommand(command)); //Invoke the command and return the results and errors ICollection <PSObject> results = pipeline.Invoke(); Errors = pipeline.Error; pipeline = null; return(results); }