/// <summary> /// Creates a list of <see cref="LocalPrincipal"/> objects /// ready to be processed by the cmdlet. /// </summary> /// <param name="groupId"> /// Name or SID (as a string) of the group we'll be removing from. /// This string is used primarily for specifying the target /// in WhatIf scenarios. /// </param> /// <param name="member"> /// LocalPrincipal object to be processed /// </param> /// <returns> /// LocalPrincipal object processed and ready to be removed /// </returns> /// <remarks> /// <para> /// LocalPrincipal object in the Member parameter may not be complete, /// particularly those created from a name or a SID string given to the /// Member cmdlet parameter. The object returned from this method contains at the very least, contain a valid SID. /// </para> /// <para> /// Any Member object provided by name or SID string will be looked up /// to ensure that such an object exists. If an object is not found, /// an error message is displayed by PowerShell and null will be returned from this method /// </para> /// <para> /// This method also handles the WhatIf scenario. If the Cmdlet's /// <b>ShouldProcess</b> method returns false on any Member object /// </para> /// </remarks> private LocalPrincipal MakePrincipal(string groupId, LocalPrincipal member) { LocalPrincipal principal = null; // if the member has a SID, we can use it directly if (member.SID != null) { principal = member; } else // otherwise it must have been constructed by name { SecurityIdentifier sid = this.TrySid(member.Name); if (sid != null) { member.SID = sid; principal = member; } else { try { principal = sam.LookupAccount(member.Name); } catch (Exception ex) { WriteError(ex.MakeErrorRecord()); } } } if (CheckShouldProcess(principal, groupId)) { return(principal); } return(null); }