日期:2014-05-18 浏览次数:20375 次
private DataTable ADGroup; private void InitialADGroupTableSchema() { ADGroup = new DataTable("ADGSSGroup"); ADGroup.Columns.Add("ID", typeof(string)); ADGroup.Columns.Add("Name", typeof(string)); ADGroup.Columns.Add("Description", typeof(string)); ADGroup.Columns.Add("GroupType", typeof(int)); ADGroup.Columns.Add("Owner", typeof(string)); ADGroup.Columns.Add("Coowner", typeof(string)); ADGroup.Columns.Add("CreatedDate", typeof(DateTime)); ADGroup.Columns.Add("ChangedDate", typeof(DateTime)); ADGroup.Columns.Add("IsGSSGroup", typeof(bool)); ADGroup.Columns.Add("AutoAcceptOUChange", typeof(bool)); ADGroup.Columns.Add("CompanyCode", typeof(string)); ADGroup.Columns.Add("AutoExpiredDate", typeof(DateTime)); ADGroup.Columns.Add("ParentGroups", typeof(string)); } private DataRow GetDataRowFromADEntry(DirectoryEntry ADEntry) { string objName = ADEntry.Name.Remove(0, 3); // DataRow dr = ADGroup.NewRow(); dr["ID"] = objName; dr["name"] = objName; dr["Description"] = Equals(ADEntry.Properties["Description"].Value, null) ? string.Empty : ADEntry.Properties["Description"].Value.ToString(); dr["Owner"] = string.Empty; dr["Coowner"] = string.Empty; dr["IsGSSGroup"] = true; dr["AutoAcceptOUChange"] = true; dr["GroupType"] = int.Parse(ADEntry.Properties["groupType"].Value.ToString()); dr["CreatedDate"] = DateTime.Parse(ADEntry.Properties["whenCreated"].Value.ToString()); dr["ChangedDate"] = DateTime.Parse(ADEntry.Properties["whenChanged"].Value.ToString()); dr["CompanyCode"] = GetCompanyCode(ADEntry.Path); dr["AutoExpiredDate"] = DateTime.Now.AddMonths(12); DirectoryEntry deParent = ADEntry.Parent; dr["ParentGroups"] = deParent.SchemaClassName.ToLower().Equals("group") ? deParent.Name.Remove(0, 3) : string.Empty; return dr; } private void FetchNestedGroups(string groupDN) { using (var groupDE = new DirectoryEntry(ADServer + RootPath, UserName, Password, AuthenticationTypes.Secure)) { var ds = new DirectorySearcher { SearchRoot = groupDE, Filter = String.Format("(&(memberOf={0})(objectCategory=group)(objectClass=group))", groupDN), ReferralChasing = ReferralChasingOption.All }; ds.PropertiesToLoad.Add("GRPOBJID"); ds.PropertiesToLoad.Add("name"); ds.PropertiesToLoad.Add("description"); ds.PropertiesToLoad.Add("groupType"); ds.PropertiesToLoad.Add("whenCreated"); ds.PropertiesToLoad.Add("whenC