public static void ImportFromActiveDirectory(string ldapPath, ContainerInfo importDestinationContainer, bool importSubOU) { try { ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer, importSubOU); Runtime.SaveConnectionsAsync(); } catch (Exception ex) { Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromActiveDirectory() failed.", ex, logOnly: true); } }
public static void ImportFromActiveDirectory(string ldapPath, ContainerInfo importDestinationContainer, bool importSubOu) { try { using (Runtime.ConnectionsService.BatchedSavingContext()) { ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer, importSubOu); } } catch (Exception ex) { Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromActiveDirectory() failed.", ex); } }
private void ImportComputers(string ldapPath, ContainerInfo parentContainer) { try { const string ldapFilter = "(|(objectClass=computer)(objectClass=organizationalUnit))"; using (var ldapSearcher = new DirectorySearcher()) { ldapSearcher.SearchRoot = new DirectoryEntry(ldapPath); ldapSearcher.Filter = ldapFilter; ldapSearcher.SearchScope = SearchScope.OneLevel; ldapSearcher.PropertiesToLoad.AddRange(new[] { "securityEquals", "cn", "objectClass" }); var ldapResults = ldapSearcher.FindAll(); foreach (SearchResult ldapResult in ldapResults) { using (var directoryEntry = ldapResult.GetDirectoryEntry()) { if (directoryEntry.Properties["objectClass"].Contains("organizationalUnit")) { // check/continue here so we don't create empty connection objects if (!_importSubOu) { continue; } // TODO - this is a circular call. A deserializer should not call an importer ActiveDirectoryImporter.Import(ldapResult.Path, parentContainer, _importSubOu); continue; } DeserializeConnection(directoryEntry, parentContainer); } } } } catch (Exception ex) { Runtime.MessageCollector.AddExceptionMessage("Config.Import.ActiveDirectory.ImportComputers() failed.", ex); } }