/// <summary> /// Process groups requested by -Name /// </summary> /// <remarks> /// All arguments to -Name will be treated as names, /// even if a name looks like a SID. /// Groups may be specified using wildcards. /// </remarks> private void ProcessNames() { if (Name != null) { foreach (var name in Name) { try { if (WildcardPattern.ContainsWildcardCharacters(name)) { var pattern = new WildcardPattern(name, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); foreach (var group in sam.GetMatchingLocalGroups(n => pattern.IsMatch(n))) { WriteObject(group); } } else { WriteObject(sam.GetLocalGroup(name)); } } catch (Exception ex) { WriteError(ex.MakeErrorRecord()); } } } }
/// <summary> /// ProcessRecord method. /// </summary> protected override void ProcessRecord() { try { LocalGroup group = null; if (InputObject != null) { if (CheckShouldProcess(InputObject.ToString())) { group = InputObject; } } else if (Name != null) { group = sam.GetLocalGroup(Name); if (!CheckShouldProcess(Name)) { group = null; } } else if (SID != null) { group = sam.GetLocalGroup(SID); if (!CheckShouldProcess(SID.ToString())) { group = null; } } if (group != null) { var delta = group.Clone(); delta.Description = Description; sam.UpdateLocalGroup(group, delta); } } catch (Exception ex) { WriteError(ex.MakeErrorRecord()); } }
/// <summary> /// Process group requested by -Name /// </summary> /// <remarks> /// Arguments to -Name will be treated as names, /// even if a name looks like a SID. /// </remarks> private void ProcessName() { if (Name != null) { try { if (CheckShouldProcess(Name, NewName)) { sam.RenameLocalGroup(sam.GetLocalGroup(Name), NewName); } } catch (Exception ex) { WriteError(ex.MakeErrorRecord()); } } }
/// <summary> /// Process groups requested by -Name /// </summary> /// <remarks> /// All arguments to -Name will be treated as names, /// even if a name looks like a SID. /// </remarks> private void ProcessNames() { if (Name != null) { foreach (var name in Name) { try { if (CheckShouldProcess(name)) { sam.RemoveLocalGroup(sam.GetLocalGroup(name)); } } catch (Exception ex) { WriteError(ex.MakeErrorRecord()); } } } }
/// <summary> /// Remove members from a group specified by name. /// </summary> /// <param name="name"> /// The name of the group from which the members will be removed. /// </param> private void ProcessName(string name) { ProcessGroup(sam.GetLocalGroup(name)); }
private IEnumerable <LocalPrincipal> ProcessName(string name) { return(ProcessGroup(sam.GetLocalGroup(name))); }