private bool ProccessUsers(SecurityPrincipalInfoListResult response) { ConsentStatusModel model = null; bool found = false; if (ExactMatch) { SecurityPrincipalInfo userconsent = null; userconsent = response.SecurityPrincipalInfoList.FirstOrDefault(user => user.SecurityPrincipal.SecurityPrincipalType == PrincipalType.User && String.Equals(user.SecurityPrincipal.Name, UserUpn, StringComparison.OrdinalIgnoreCase)); if (userconsent == null) { WriteErrorWithTimestamp("User: "******" does not exist in collection " + CollectionName); found = false; } else { model = new ConsentStatusModel(userconsent); WriteObject(model); found = true; } } else { IEnumerable <SecurityPrincipalInfo> spList = null; if (showAllUsers) { spList = response.SecurityPrincipalInfoList.Where(user => user.SecurityPrincipal.SecurityPrincipalType == PrincipalType.User); } else { spList = response.SecurityPrincipalInfoList.Where(user => user.SecurityPrincipal.SecurityPrincipalType == PrincipalType.User && Wildcard.IsMatch(user.SecurityPrincipal.Name)); } if (spList != null && spList.Count() > 0) { List <SecurityPrincipalInfo> userConsents = new List <SecurityPrincipalInfo>(spList); IComparer <SecurityPrincipalInfo> comparer = new ServicePrincipalComparer(); userConsents.Sort(comparer); foreach (SecurityPrincipalInfo consent in userConsents) { model = new ConsentStatusModel(consent); WriteObject(model); } found = true; } } return(found); }
public override void ExecuteCmdlet() { SecurityPrincipalInfoListResult response = null; ConsentStatusModel model = null; bool showAllUsers = String.IsNullOrWhiteSpace(UserUpn); bool found = false; if (showAllUsers == false) { CreateWildcardPattern(UserUpn); } response = CallClient(() => Client.Principals.List(CollectionName), Client.Principals); if (response != null && response.SecurityPrincipalInfoList != null) { if (ExactMatch) { SecurityPrincipalInfo userconsent = null; userconsent = response.SecurityPrincipalInfoList.FirstOrDefault(user => user.SecurityPrincipal.SecurityPrincipalType == PrincipalType.User && String.Equals(user.SecurityPrincipal.Name, UserUpn, StringComparison.OrdinalIgnoreCase)); if (userconsent == null) { WriteErrorWithTimestamp("User: "******" does not exist in collection " + CollectionName); found = false; } else { model = new ConsentStatusModel(userconsent); WriteObject(model); found = true; } } else { IEnumerable <SecurityPrincipalInfo> spList = null; if (showAllUsers) { spList = response.SecurityPrincipalInfoList.Where(user => user.SecurityPrincipal.SecurityPrincipalType == PrincipalType.User); } else { spList = response.SecurityPrincipalInfoList.Where(user => user.SecurityPrincipal.SecurityPrincipalType == PrincipalType.User && Wildcard.IsMatch(user.SecurityPrincipal.Name)); } if (spList != null && spList.Count() > 0) { List <SecurityPrincipalInfo> userConsents = new List <SecurityPrincipalInfo>(spList); IComparer <SecurityPrincipalInfo> comparer = new ServicePrincipalComparer(); userConsents.Sort(comparer); foreach (SecurityPrincipalInfo consent in spList) { model = new ConsentStatusModel(consent); WriteObject(model); } found = true; } } } if (!found && !showAllUsers) { WriteVerboseWithTimestamp(String.Format("User '{0}' is not assigned to Collection '{1}'.", UserUpn, CollectionName)); } }