private IEnumerable <LocalPrincipal> ProcessesMembership(IEnumerable <LocalPrincipal> membership)
        {
            List <LocalPrincipal> rv;

            // if no members are specified, return all of them
            if (Member == null)
            {
                //return membership;
                rv = new List <LocalPrincipal>(membership);
            }
            else
            {
                //var rv = new List<LocalPrincipal>();
                rv = new List <LocalPrincipal>();

                if (WildcardPattern.ContainsWildcardCharacters(Member))
                {
                    var pattern = new WildcardPattern(Member, WildcardOptions.Compiled
                                                      | WildcardOptions.IgnoreCase);

                    foreach (var m in membership)
                    {
                        if (pattern.IsMatch(sam.StripMachineName(m.Name)))
                        {
                            rv.Add(m);
                        }
                    }
                }
                else
                {
                    var sid = this.TrySid(Member);

                    if (sid != null)
                    {
                        foreach (var m in membership)
                        {
                            if (m.SID == sid)
                            {
                                rv.Add(m);
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (var m in membership)
                        {
                            if (sam.StripMachineName(m.Name).Equals(Member, StringComparison.CurrentCultureIgnoreCase))
                            {
                                rv.Add(m);
                                break;
                            }
                        }
                    }

                    if (rv.Count == 0)
                    {
                        var ex = new PrincipalNotFoundException(member, member);
                        WriteError(ex.MakeErrorRecord());
                    }
                }
            }

            // sort the resulting principals by mane
            rv.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.CurrentCultureIgnoreCase));

            return(rv);
        }
        private IEnumerable<LocalPrincipal> ProcessesMembership(IEnumerable<LocalPrincipal> membership)
        {
            List<LocalPrincipal> rv;

            // if no members are specified, return all of them
            if (Member == null)
            {
                //return membership;
                rv = new List<LocalPrincipal>(membership);
            }
            else
            {
                //var rv = new List<LocalPrincipal>();
                rv = new List<LocalPrincipal>();

                if (WildcardPattern.ContainsWildcardCharacters(Member))
                {
                    var pattern = new WildcardPattern(Member, WildcardOptions.Compiled
                                                                | WildcardOptions.IgnoreCase);

                    foreach (var m in membership)
                        if (pattern.IsMatch(sam.StripMachineName(m.Name)))
                            rv.Add(m);
                }
                else
                {
                    var sid = this.TrySid(Member);

                    if (sid != null)
                    {
                        foreach (var m in membership)
                        {
                            if (m.SID == sid)
                            {
                                rv.Add(m);
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (var m in membership)
                        {
                            if (sam.StripMachineName(m.Name).Equals(Member, StringComparison.CurrentCultureIgnoreCase))
                            {
                                rv.Add(m);
                                break;
                            }
                        }
                    }

                    if (rv.Count == 0)
                    {
                        var ex = new PrincipalNotFoundException(member, member);
                        WriteError(ex.MakeErrorRecord());
                    }
                }
            }

            // sort the resulting principals by mane
            rv.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.CurrentCultureIgnoreCase));

            return rv;
        }