private object ConvertToPropertyType(DirectoryEntryProperty targetProperty, object source) { if (targetProperty is IDistinguishedNameProperty) { string[] dns = GetDistinguishedNames(source); if (dns.Length == 1) { return(dns[0]); } return(dns); } return(source); }
private void AddItemProperty(PSObject retval, DirectoryEntryProperty dep) { if (dep.CanRead) { string name = dep.Name; object value = dep.GetValue(); if (dep is IDistinguishedNameProperty) { String stringValue = value as String; ICollection listValue = value as ICollection; if (listValue != null) { List <DirectoryEntryInfo> infoList = new List <DirectoryEntryInfo>(); foreach (string dn in listValue) { DirectoryEntry entry = CurrentProvider.GetEntry(dn); DirectoryEntryInfo info = CurrentProvider.GetEntryInfo(entry); infoList.Add(info); } value = infoList; } else if (stringValue != null) { DirectoryEntry entry = CurrentProvider.GetEntry(stringValue); DirectoryEntryInfo info = CurrentProvider.GetEntryInfo(entry); value = info; } } retval.Members.Add(new PSNoteProperty(name, value)); } }