public static void CreateAdamSite(string targetName, string newSiteName) { try { // assemble the connection string using the host name and the port assigned to ADAM string adamConnectionString = targetName; DirectoryContext adamContext = new DirectoryContext( DirectoryContextType.DirectoryServer, adamConnectionString); ActiveDirectorySite site = new ActiveDirectorySite(adamContext, newSiteName); // set site options site.Options = ActiveDirectorySiteOptions.GroupMembershipCachingEnabled; // commit the site to the directory site.Save(); Console.WriteLine("\nSite \"{0}\" was created successfully", site); } catch (Exception e) { Console.WriteLine("\r\nUnexpected exception occured:\n\t{0}\n{1}", e.GetType().Name, e.Message); } }
public static void CreateAdSite(string siteName) { try { // get a forest context DirectoryContext forestContext = new DirectoryContext( DirectoryContextType.Forest); // create a new site ActiveDirectorySite site = new ActiveDirectorySite(forestContext, siteName); // set site options site.Options = ActiveDirectorySiteOptions.GroupMembershipCachingEnabled; // commit the site to the directory site.Save(); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nSite \"{0}\" was created successfully", site); Console.ResetColor(); } catch (Exception e) { Console.WriteLine("\r\nUnexpected exception occured:\n\t{0}\n{1}", e.GetType().Name, e.Message); } }