protected override void ProcessRecord() { var baseResourceList = new List <EnvironmentResource>(); var environmentNameList = EnvironmentName?.ToList().ConvertAll(s => s.ToLower()); switch (this.ParameterSetName) { case All: baseResourceList = _connection.Repository.Environments.FindAll(); break; case ByName: //Multiple values but one of them is wildcarded, which is not an accepted scenario (I.e -MachineName WebServer*, Database1) if (environmentNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && environmentNameList.Count > 1)) { throw OctoposhExceptions.ParameterCollectionHasRegularAndWildcardItem("EnvironmentName"); } //Only 1 wildcarded value (ie -MachineName WebServer*) else if (environmentNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && environmentNameList.Count == 1)) { var pattern = new WildcardPattern(environmentNameList.First().ToLower()); baseResourceList = _connection.Repository.Environments.FindMany(x => pattern.IsMatch(x.Name.ToLower())); } //multiple non-wildcared values (i.e. -MachineName WebServer1,Database1) else if (!environmentNameList.Any(WildcardPattern.ContainsWildcardCharacters)) { baseResourceList = _connection.Repository.Environments.FindMany(x => environmentNameList.Contains(x.Name.ToLower())); } break; } if (ResourceOnly) { if (baseResourceList.Count == 1) { WriteObject(baseResourceList.FirstOrDefault(), true); } else { WriteObject(baseResourceList, true); } } else { var converter = new OutputConverter(); var outputList = converter.GetOctopusEnvironment(baseResourceList); if (outputList.Count == 1) { WriteObject(outputList.FirstOrDefault(), true); } else { WriteObject(outputList, true); } } }