/// <summary> /// Process users requested by -Name. /// </summary> /// <remarks> /// All arguments to -Name will be treated as names, /// even if a name looks like a SID. /// Users may be specified using wildcards. /// </remarks> private void ProcessNames() { if (Name != null) { foreach (var nm in Name) { try { if (WildcardPattern.ContainsWildcardCharacters(nm)) { var pattern = new WildcardPattern(nm, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); foreach (var user in sam.GetMatchingLocalUsers(n => pattern.IsMatch(n))) { WriteObject(user); } } else { WriteObject(sam.GetLocalUser(nm)); } } catch (Exception ex) { WriteError(ex.MakeErrorRecord()); } } } }