PageRenderTime 71ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/CommandLine/ADModifyMain.cs

#
C# | 3072 lines | 2468 code | 316 blank | 288 comment | 181 complexity | 2118bbae88426453d678a4c781974638 MD5 | raw file
  1. using System;
  2. using System.DirectoryServices;
  3. using ADModify.Library;
  4. using System.Xml;
  5. using System.IO;
  6. using Microsoft.Win32;
  7. namespace ADModify
  8. {
  9. /// <summary>
  10. /// Main is the program entry point. In main we check for arguments and change global variables depending on what
  11. /// was entered. If we have in fact found valid attribute switches, then the GetDN method is called. This Method
  12. /// does the initial LDAP query to find the DN for all users matching the LDAP filter specified.
  13. ///
  14. /// Once the have the users we test all globals for a non null value for string and a true value for boolean. If
  15. /// these test true, then we call the specified method from the ModifyAttributes class and pass all necesarry parameters.
  16. /// Modification and reporting is done within the methods of the ModifyAttributes and LogFile classes.
  17. /// </summary>
  18. class ADModifyMain
  19. {
  20. //public variables
  21. //set all string values to null and all bool values to false
  22. //later on we test these conditions and execute the modify only if string values
  23. //are !null and bool values are true
  24. public static int usercount = 0;
  25. public static int querycount = 0;
  26. //ldap settings
  27. public static string servername = null;
  28. public static int pageSize = 1000;
  29. //Terminal Server Attributes
  30. public static string TSProfilePath = null;
  31. public static string TSFolderPath = null;
  32. public static string TSHomeDrive = null;
  33. public static bool TSEnable = false;
  34. public static bool TSDisable = false;
  35. public static bool RemoteEnable = false;
  36. public static bool RemoteDisable = false;
  37. public static bool RequirePermission = false;
  38. public static string program = null;
  39. public static string startIn = null;
  40. public static bool InteractWithSession = false;
  41. public static bool SetDisconnectTime = false;
  42. public static int DisconnectTime;
  43. public static bool SetMaxConnectionTime = false;
  44. public static int MaxConnectionTime;
  45. public static bool SetMaxIdleTime = false;
  46. public static int MaxIdleTime;
  47. public static bool SetEndSession = false;
  48. public static bool EndSession = false;
  49. public static bool SetOriginatingOnly = false;
  50. public static bool OriginatingOnly = false;
  51. public static bool SetConnectClientDrives = false;
  52. public static bool ConnectClientDrives = false;
  53. public static bool SetConnectClientPrinters = false;
  54. public static bool ConnectClientPrinters = false;
  55. public static bool SetDefaultToMainPrinter = false;
  56. public static bool DefaultToMainPrinter = false;
  57. //Exchange related attributes
  58. public static bool killmail = false;
  59. public static bool includeinrecipientpolicy = false;
  60. public static bool excludefromrecipientpolicy = false;
  61. public static bool includeinmailboxmanager = false;
  62. public static bool excludefrommailboxmanager = false;
  63. public static bool enablehttp = false;
  64. public static bool disablehttp = false;
  65. public static bool enablepop3 = false;
  66. public static bool disablepop3 = false;
  67. public static bool enableimap4 = false;
  68. public static bool disableimap4 = false;
  69. public static bool enablemapi = false;
  70. public static bool disablemapi = false;
  71. public static bool enablecachedmapi = false;
  72. public static bool EnableOMA = false;
  73. public static bool EnableUIS = false;
  74. public static bool EnableUTD = false;
  75. public static string smtpaddress = null;
  76. public static bool setasprimary = false;
  77. public static bool updatemail = false;
  78. public static bool removeaddress = false;
  79. public static bool keepprimary = false;
  80. public static string addresstoremove = null;
  81. public static bool showinaddresslists = false;
  82. public static bool hidefromaddresslists = false;
  83. public static bool SetMailboxRights = false;
  84. public static bool ClearMailboxRights = false;
  85. public static bool FixSendAs = false;
  86. public static bool GrantSelfAEA = false;
  87. public static bool RemoveAEAFromSelf = false;
  88. public static bool RemoveSendAs = false;
  89. public static bool GrantSelfFullAndRead = false;
  90. public static bool RemoveSelfFullAndRead = false;
  91. public static bool DumpMailboxRights = false;
  92. //User Account Settings
  93. public static bool disableaccount = false;
  94. public static bool enableaccount = false;
  95. public static bool PasswordNotRequired = false;
  96. public static bool SetPasswordNotRequired = false;
  97. public static bool SetPasswordNeverExpires = false;
  98. public static bool PasswordNeverExpires = false;
  99. public static bool MustChangePasswd = false;
  100. public static bool SetMustChangePassword = false;
  101. public static bool CannotChangePasswd = false;
  102. public static bool SetCannotChangePassword = false;
  103. public static bool UseReversibleEncryption = false;
  104. public static bool SetUseReversibleEncryption = false;
  105. public static bool SetRequireSmartCard = false;
  106. public static bool RequireSmartCard = false;
  107. public static bool SetCannotBeDelegated = false;
  108. public static bool CannotBeDelegated = false;
  109. public static bool SetUseDESEncryption = false;
  110. public static bool UseDESEncryption = false;
  111. public static bool SetDoNotRequireKerberosPreAuth = false;
  112. public static bool DoNotRequireKerberosPreAuth = false;
  113. public static bool AddMembersToGroup = false;
  114. public static bool SetAccountExpires = false;
  115. public static string ExpireTime = null;
  116. public static bool RemoveMembersFromGroup = false;
  117. public static string DNOfGroup = null;
  118. public static bool ModifyRDN = false;
  119. public static string NewRDN = null;
  120. //Permissions Settings
  121. public static bool Setallowinheritable = false;
  122. public static bool AllowInheritable = false;
  123. public static bool DumpDacl = false;
  124. public static bool DumpDaclInheritance = false;
  125. //custom attribute set
  126. public static string customAttributeName = null;
  127. public static string customAttributeValue = null;
  128. public static bool multi = false;
  129. public static bool remove = false;
  130. //undo mode
  131. public static bool UndoMode = false;
  132. public static string logFileName = null;
  133. //mailbox rights
  134. public static bool GrantSendAsRights = false;
  135. public static bool ImportMailboxRights = false;
  136. public static bool ModifyMailboxRights = false;
  137. public static bool RemoveMailboxRights = false;
  138. public static string Trustee = null;
  139. public static string Permission = null;
  140. public static bool Deny = false;
  141. public static bool MailboxRightsOverwrite = false;
  142. //timer
  143. public static float timeElapsed = 0;
  144. //progress bar
  145. public static int UserCountDividedWhole;
  146. public static float UserCountDividedDecimalCount;
  147. public static float UserCountDividedDecimalCountConst;
  148. public static int dots;
  149. /// <summary>
  150. ///
  151. /// ADModifyMain::GetDN
  152. ///
  153. /// Accepts:
  154. /// logWriter - Handle to Writer object for logging
  155. /// LDAPFilter - the LDAP filter used for object search
  156. /// SearchBase - the DN to begin the query
  157. /// subtree - boolean specifies either onelevel or subtree
  158. ///
  159. /// Returns:
  160. /// none
  161. ///
  162. /// GetDN accepts the Search Base, Scope, and LDAP Filter from args.
  163. /// GetDN runs the query and returns the list of users that match.
  164. /// At that point we test all public variables. If a value other than the default
  165. /// is set, we call ADModify!ModifyAttributes::* to modify the object and pass all
  166. /// appropriate arguments.
  167. /// </summary>
  168. static void GetDN(XmlWriter logWriter, string LDAPFilter, bool subtree, string SearchBase)
  169. {
  170. //Before doing anything, verify the server and base DN entered are valid
  171. if(servername!=null)
  172. {
  173. try
  174. {
  175. //do this to test if we can even connect to the server
  176. DirectoryEntry ent = new DirectoryEntry("LDAP://" + servername + "/" + SearchBase);
  177. string myTempVar = ent.Parent.ToString(); //if the servername is invalid, this line will raise an exception
  178. ent.Dispose();
  179. }
  180. catch(System.Exception caught)
  181. {
  182. if(caught.Message=="The server is not operational")
  183. {
  184. Console.WriteLine("\nAn error has occurred connecting to server " + servername + ".");
  185. Console.WriteLine("The error was: " + caught.Message + "\n");
  186. }
  187. else if(caught.Message=="A referral was returned from the server" || caught.Message=="There is no such object on the server")
  188. {
  189. Console.WriteLine("\nAn error has occured binding to Base DN " + SearchBase + ".");
  190. Console.WriteLine("The error was: " + caught.Message + ".");
  191. Console.WriteLine("Please enter a valid Base DN.\n");
  192. }
  193. else
  194. {
  195. Console.WriteLine("\nAn error has occurred binding to Active Directory.");
  196. Console.WriteLine("The error was: " + caught.Message + "\n");
  197. }
  198. return;
  199. }
  200. }
  201. //Initialize the log file
  202. LogFile log = new LogFile();
  203. //Check for mailbox rights dump mode and create logfile if necesarry
  204. XmlTextWriter DumpWriter = null;
  205. if(DumpMailboxRights)
  206. {
  207. if(File.Exists("mbxrights.xml"))
  208. {
  209. Console.WriteLine("\nThe file mbxrights.xml already exists. You must remove or rename this file before you can proceed.\n");
  210. return;
  211. }
  212. DumpWriter = new XmlTextWriter("mbxrights.xml", null);
  213. DumpWriter.WriteStartElement("MailboxRights");
  214. }
  215. //get OS version to determine supportability of TS modifications
  216. //string OSVersionFull = System.Environment.OSVersion.ToString();
  217. //string OSVersion = OSVersionFull.Substring(OSVersionFull.Length - 10, 10);
  218. //int OSVersionNoDots = Convert.ToInt32(OSVersion.Replace(".",""),10);
  219. //Check for Win2k3 so we know whether to enable terminal services options
  220. //get OS build to determine supportability of TS modifications
  221. //TODO: When longhorn releases we need to add their build number to this check
  222. System.OperatingSystem osInfo = System.Environment.OSVersion;
  223. //First things first... check for TS attributes. If there are any, check OS version before proceeding.
  224. if(TSProfilePath!=null | program!=null | startIn!=null | TSFolderPath!=null | TSHomeDrive!=null | TSEnable | TSDisable | RemoteEnable | RemoteDisable | SetDisconnectTime | SetMaxConnectionTime | SetMaxIdleTime | SetEndSession | SetOriginatingOnly | SetConnectClientDrives | SetConnectClientPrinters | SetDefaultToMainPrinter)
  225. {
  226. if (osInfo.Version.Build != 3790)
  227. {
  228. Console.WriteLine("Operating System must be at build 5.2.3790.0 or later to support this operation.\nCurrent OS build: " + osInfo.VersionString + "\n");
  229. return;
  230. }
  231. }
  232. //Also check for CDOEXM attributes. If there are any, make sure Exchange is installed.
  233. if(FixSendAs || GrantSelfAEA || RemoveAEAFromSelf || GrantSelfFullAndRead || RemoveSelfFullAndRead || DumpMailboxRights || ImportMailboxRights || ModifyMailboxRights || RemoveMailboxRights)
  234. {
  235. RegistryKey myRegKey = Registry.LocalMachine;
  236. RegistryKey mySubKey = myRegKey.OpenSubKey("Software\\Microsoft\\Exchange\\Setup");
  237. string ExchangeVersion = mySubKey.GetValue("NewestBuild").ToString();
  238. int ExchangeVersionInt = Convert.ToInt32(ExchangeVersion,10);
  239. if(ExchangeVersionInt<4417)
  240. {
  241. Console.WriteLine("Exchange Server must be installed and must be at build 4417 or later to support this modification.\nCurrent Exchange Build: " + ExchangeVersion + "\n");
  242. return;
  243. }
  244. }
  245. //bind to AD using the SearchBase specified by the user
  246. DirectoryEntry de = new DirectoryEntry("LDAP://" + SearchBase);
  247. //set searcher object with our LDAP filter
  248. DirectorySearcher src = new DirectorySearcher(LDAPFilter);
  249. src.SearchRoot = de;
  250. //set our search scope
  251. if(subtree)
  252. src.SearchScope = SearchScope.Subtree;
  253. else
  254. src.SearchScope = SearchScope.OneLevel;
  255. //Other settings for search
  256. src.PageSize = pageSize;
  257. src.PropertiesToLoad.Add("distinguishedName");
  258. SearchResultCollection results = null;
  259. //execute the query
  260. try
  261. {
  262. results = src.FindAll();
  263. }
  264. catch(System.Exception caught)
  265. {
  266. Console.WriteLine("An error occured while executing the query. The error was: {0}", caught.Message + "\n");
  267. return;
  268. }
  269. Console.WriteLine("\nIssuing Query....\n");
  270. if(results.Count == 1)
  271. {
  272. Console.WriteLine("1 item found matching the specified filter.");
  273. }
  274. if(results.Count >= 2)
  275. {
  276. Console.WriteLine(results.Count + " items found matching the specified filter.");
  277. }
  278. if(results.Count == 0)
  279. {
  280. Console.WriteLine("No items found matching the specified filter.\n");
  281. return;
  282. }
  283. Console.WriteLine("");
  284. //for progress bar
  285. float UserCountDivided = 50/(float)results.Count; //this number remains constant
  286. float UserCountDividedTemp = UserCountDivided; //this number we increment
  287. dots = 0; //number of dots shown so far on progress bar
  288. UserCountDividedWhole = 0; //number on left side of decimal to increment
  289. UserCountDividedDecimalCount = 0; //number on right side of decimal to increment
  290. UserCountDividedDecimalCountConst = 0; //number on right side of decimal, stays contstant
  291. string UserCountDividedDecimalCountString = null;
  292. string[] UserCountDividedString = UserCountDivided.ToString().Split('.'); //split at the decimal
  293. //calculate the whole and decimal increment counters
  294. UserCountDividedWhole = Convert.ToInt16(UserCountDividedString[0],10); //grab the whole number on the left
  295. if(UserCountDividedString.GetUpperBound(0) == 1)
  296. {
  297. UserCountDividedDecimalCountString = UserCountDividedString[1].Replace(".", "");
  298. UserCountDividedDecimalCountString = "." + UserCountDividedDecimalCountString;
  299. UserCountDividedDecimalCount = float.Parse(UserCountDividedDecimalCountString);
  300. }
  301. else
  302. {
  303. UserCountDividedDecimalCount = 0;
  304. }
  305. UserCountDividedDecimalCountConst = UserCountDividedDecimalCount;
  306. Console.WriteLine("");
  307. Console.WriteLine("0% 50% 100%");
  308. Console.WriteLine("|----|----|----|----|----|----|----|----|----|----|");
  309. Console.Write(".");
  310. dots++;
  311. //increment the user count
  312. usercount++;
  313. ModifyAttributes admod = new ModifyAttributes(); //from ADModify.Library.dll
  314. string UserDN;
  315. //iterate the query results
  316. for(int modusers=0; modusers<=results.Count-1; modusers++)
  317. {
  318. if(dots<=50) //just to be safe, make sure we're under out dots quota so we don't
  319. { //exceed the 100% mark
  320. for(int b=0; b<= UserCountDividedWhole-1; b++)
  321. {
  322. if(dots<=50)
  323. {
  324. Console.Write(".");
  325. dots++;
  326. }
  327. }
  328. if(UserCountDividedDecimalCount>=1)
  329. {
  330. if(dots<=50)
  331. {
  332. UserCountDividedDecimalCount--;
  333. Console.Write(".");
  334. dots++;
  335. }
  336. }
  337. UserCountDividedDecimalCount = UserCountDividedDecimalCount + UserCountDividedDecimalCountConst;
  338. }
  339. if(modusers==results.Count-1 & dots < 51) //sometimes the decimal math doesn't leave us with a
  340. { //51st dot so we have to add it ourselves.
  341. Console.Write(".");
  342. }
  343. if(modusers==results.Count-1) //finish off the progress bar
  344. {
  345. Console.WriteLine("");
  346. Console.WriteLine("");
  347. }
  348. UserDN = results[modusers].Path;
  349. string UserDNWithLDAP = UserDN;
  350. string UserDNWithoutLDAP = UserDNWithLDAP.Remove(0, 7); //trim the LDAP:// off the name in case we need to append servername
  351. //check for servername. If its null we just pass UserDN as UserDNWithLDAP.
  352. //If it has a value we append it and add the LDAP:// back
  353. if(servername==null)
  354. {
  355. UserDN = UserDNWithLDAP;
  356. }
  357. else
  358. {
  359. UserDN = "LDAP://" + servername + "/" + UserDNWithoutLDAP;
  360. }
  361. //test each public variable for a value, if a value other than null exists for string values or
  362. //a true value exists for boolean values then we loop the users through the applicable methods
  363. //Terminal Server Attributes
  364. if(TSProfilePath!=null)
  365. {
  366. admod.TSChangeTermServProfile(logWriter, UserDN, TSProfilePath);
  367. }
  368. if(TSFolderPath!=null & TSHomeDrive==null)
  369. {
  370. admod.TSChangeTermServFolder(logWriter, UserDN, TSFolderPath);
  371. }
  372. if(TSHomeDrive!=null)
  373. {
  374. admod.TSChangeTermServDrive(logWriter, UserDN, TSHomeDrive, TSFolderPath);
  375. }
  376. if(TSEnable)
  377. {
  378. admod.TSEnableLogon(logWriter, UserDN);
  379. }
  380. if(TSDisable)
  381. {
  382. admod.TSDisableLogon(logWriter, UserDN);
  383. }
  384. if(RemoteEnable)
  385. {
  386. admod.TSAllowRemoteControl(logWriter, UserDN, RequirePermission, InteractWithSession);
  387. }
  388. if(RemoteDisable)
  389. {
  390. admod.TSDisableRemoteControl(logWriter, UserDN);
  391. }
  392. if(SetDisconnectTime)
  393. {
  394. admod.TSMaxDisconnectedSessionTime(logWriter, UserDN, DisconnectTime);
  395. }
  396. if(program!=null)
  397. {
  398. admod.TSRunProgramAtStartup(logWriter, UserDN, program);
  399. }
  400. if(startIn!=null)
  401. {
  402. admod.TSRunProgramAtStartupStartIn(logWriter, UserDN, startIn);
  403. }
  404. if(SetMaxConnectionTime)
  405. {
  406. admod.TSMaxConnectionTime(logWriter, UserDN, MaxConnectionTime);
  407. }
  408. if(SetMaxIdleTime)
  409. {
  410. admod.TSMaxIdleTime(logWriter, UserDN, MaxIdleTime);
  411. }
  412. if(SetEndSession)
  413. {
  414. admod.TSEndSessionAction(logWriter, UserDN, EndSession);
  415. }
  416. if(SetOriginatingOnly)
  417. {
  418. admod.TSAllowReconnectAction(logWriter, UserDN, OriginatingOnly);
  419. }
  420. if(SetConnectClientDrives)
  421. {
  422. admod.TSConnectClientDrivesAtLogon(logWriter, UserDN, ConnectClientDrives);
  423. }
  424. if(SetConnectClientPrinters)
  425. {
  426. admod.TSConnectClientPrintersAtLogon(logWriter, UserDN, ConnectClientPrinters);
  427. }
  428. if(SetDefaultToMainPrinter)
  429. {
  430. admod.TSDefaultToMainPrinter(logWriter, UserDN, DefaultToMainPrinter);
  431. }
  432. //Exchange Related Attributes
  433. if(showinaddresslists)
  434. {
  435. admod.ShowInAddressLists(logWriter, UserDN);
  436. }
  437. if(hidefromaddresslists)
  438. {
  439. admod.HideFromAddressLists(logWriter, UserDN);
  440. }
  441. if(killmail)
  442. {
  443. admod.KillMail(logWriter, UserDN);
  444. }
  445. if(includeinrecipientpolicy)
  446. {
  447. admod.IncludeInRecipientPolicy(logWriter, UserDN);
  448. }
  449. if(excludefromrecipientpolicy)
  450. {
  451. admod.ExcludeFromRecipientPolicy(logWriter, UserDN);
  452. }
  453. if(includeinmailboxmanager)
  454. {
  455. admod.IncludeInMailboxManager(logWriter, UserDN);
  456. }
  457. if(excludefrommailboxmanager)
  458. {
  459. admod.ExcludeFromMailboxManager(logWriter, UserDN);
  460. }
  461. if(enablehttp)
  462. {
  463. admod.EnableHTTP(logWriter, UserDN);
  464. }
  465. if(disablehttp)
  466. {
  467. admod.DisableHTTP(logWriter, UserDN);
  468. }
  469. if(enablepop3)
  470. {
  471. admod.EnablePOP3(logWriter, UserDN);
  472. }
  473. if(disablepop3)
  474. {
  475. admod.DisablePOP3(logWriter, UserDN);
  476. }
  477. if(enableimap4)
  478. {
  479. admod.EnableIMAP4(logWriter, UserDN);
  480. }
  481. if(disableimap4)
  482. {
  483. admod.DisableIMAP4(logWriter, UserDN);
  484. }
  485. if(enablemapi)
  486. {
  487. admod.ChangeMAPISettings(logWriter, UserDN, "MAPI§1§0§§§§§§");
  488. }
  489. if(disablemapi)
  490. {
  491. admod.ChangeMAPISettings(logWriter, UserDN, "MAPI§0§0§§§§§§");
  492. }
  493. if(enablecachedmapi)
  494. {
  495. admod.ChangeMAPISettings(logWriter, UserDN, "MAPI§1§1§§§§§§");
  496. }
  497. if(smtpaddress!=null)
  498. {
  499. admod.SetSMTPAddress(logWriter, UserDN, smtpaddress, setasprimary);
  500. }
  501. if(updatemail==true)
  502. {
  503. admod.SetCustomAttribute(logWriter, UserDN, "mail", smtpaddress, false, false);
  504. }
  505. if(removeaddress)
  506. {
  507. if(keepprimary)
  508. {
  509. admod.RemoveEmailAddress(logWriter, UserDN, addresstoremove, true);
  510. }
  511. else
  512. {
  513. admod.RemoveEmailAddress(logWriter, UserDN, addresstoremove, false);
  514. }
  515. }
  516. if(SetMailboxRights)
  517. {
  518. admod.SetmsExchMailboxSecurityDescriptor(logWriter, UserDN);
  519. }
  520. if(GrantSendAsRights)
  521. {
  522. admod.AddSendAs(logWriter, UserDN, Trustee, Deny);
  523. }
  524. if(FixSendAs)
  525. {
  526. admod.GiveSendAsToUsersWithFullMBXAccess(logWriter, UserDN);
  527. }
  528. if(RemoveSendAs)
  529. {
  530. admod.RemoveSendAsFromUsersWithFullMBXAccess(logWriter, UserDN);
  531. }
  532. if(GrantSelfAEA)
  533. {
  534. admod.SetSelfAsAssociatedExternalAccount(logWriter, UserDN);
  535. }
  536. if(RemoveAEAFromSelf)
  537. {
  538. admod.RemoveAssociatedExternalAccountFromSelf(logWriter, UserDN);
  539. }
  540. if(GrantSelfFullAndRead)
  541. {
  542. admod.GrantSelfFullMailboxAccessAndRead(logWriter, UserDN);
  543. }
  544. if(RemoveSelfFullAndRead)
  545. {
  546. admod.RemoveFullMailboxAccessAndReadFromSelf(logWriter, UserDN);
  547. }
  548. if(DumpMailboxRights)
  549. {
  550. admod.DumpMailboxRights(logWriter, DumpWriter, UserDN);
  551. }
  552. if(ModifyMailboxRights)
  553. {
  554. admod.AddACEToMailboxRights(logWriter, UserDN, Trustee, Permission, Deny);
  555. }
  556. if(RemoveMailboxRights)
  557. {
  558. admod.RemoveACEFromMailboxRights(logWriter, UserDN, Trustee, Permission, Deny);
  559. }
  560. //User Account Settings
  561. if(disableaccount)
  562. {
  563. admod.DisableAccount(logWriter, UserDN);
  564. }
  565. if(enableaccount)
  566. {
  567. admod.EnableAccount(logWriter, UserDN);
  568. }
  569. if (SetPasswordNotRequired & PasswordNotRequired)
  570. {
  571. admod.SetPasswordNotRequired(logWriter, UserDN);
  572. }
  573. if (SetPasswordNotRequired & !PasswordNotRequired)
  574. {
  575. admod.DisablePasswordNotRequired(logWriter, UserDN);
  576. }
  577. if(SetPasswordNeverExpires)
  578. {
  579. admod.SetPasswordNeverExpires(logWriter, UserDN, PasswordNeverExpires);
  580. }
  581. if(SetMustChangePassword)
  582. {
  583. admod.MustChangePassword(logWriter, UserDN, MustChangePasswd);
  584. }
  585. if(SetCannotChangePassword)
  586. {
  587. admod.CannotChangePassword(logWriter, UserDN, CannotChangePasswd);
  588. }
  589. if(SetUseReversibleEncryption)
  590. {
  591. admod.StorePasswordWithReversibleEncryption(logWriter, UserDN, UseReversibleEncryption);
  592. }
  593. if(SetRequireSmartCard)
  594. {
  595. admod.SetRequireSmartCard(logWriter, UserDN, RequireSmartCard);
  596. }
  597. if(SetCannotBeDelegated)
  598. {
  599. admod.SetCannotBeDelegated(logWriter, UserDN, CannotBeDelegated);
  600. }
  601. if(SetUseDESEncryption)
  602. {
  603. admod.SetUseDESEncryption(logWriter, UserDN, UseDESEncryption);
  604. }
  605. if(SetDoNotRequireKerberosPreAuth)
  606. {
  607. admod.SetDoNotRequireKerberosPreAuth(logWriter, UserDN, DoNotRequireKerberosPreAuth);
  608. }
  609. if(AddMembersToGroup)
  610. {
  611. admod.AddToGroup(logWriter, UserDN, DNOfGroup);
  612. }
  613. if(RemoveMembersFromGroup)
  614. {
  615. admod.RemoveFromGroup(logWriter, UserDN, DNOfGroup);
  616. }
  617. if(ModifyRDN)
  618. {
  619. admod.SetRelativeDistinguishedName(logWriter, UserDN, NewRDN);
  620. }
  621. //Permissions Settings
  622. if(Setallowinheritable)
  623. {
  624. admod.AllowInheritablePermissions(logWriter, UserDN, AllowInheritable);
  625. }
  626. //custom attribute set
  627. if(customAttributeName!=null)
  628. {
  629. admod.SetCustomAttribute(logWriter, UserDN, customAttributeName, customAttributeValue, multi, remove);
  630. }
  631. }
  632. //finish up
  633. if(DumpMailboxRights)
  634. {
  635. DumpWriter.WriteEndElement();
  636. DumpWriter.Flush();
  637. DumpWriter.Close();
  638. }
  639. log.showResults();
  640. src.Dispose();
  641. return;
  642. }
  643. /// <summary>
  644. /// ADModifyMain::GiveCommandArgs
  645. ///
  646. /// Accepts:
  647. /// none
  648. /// Returns:
  649. /// none
  650. ///
  651. /// Displays command line usage back to the console.
  652. /// </summary>
  653. static void GiveCommandArgs()
  654. {
  655. Console.WriteLine("");
  656. Console.WriteLine("Active Directory Bulk Modify Tool Command Line Version 2.1");
  657. Console.WriteLine("");
  658. Console.WriteLine("Questions or Comments? ");
  659. Console.WriteLine("Email: admodify@microsoft.com");
  660. Console.WriteLine("");
  661. Console.WriteLine("ADModCmd runs an LDAP query against the specified AD container. The ");
  662. Console.WriteLine("modifications are then performed against the results of the query.");
  663. Console.WriteLine("");
  664. Console.WriteLine("Usage:");
  665. Console.WriteLine("");
  666. Console.WriteLine("admodcmd [-dn BaseDN] [-p pagesize] [-s] [-server servername]");
  667. Console.WriteLine(" [-f LDAPFilter] [modification]");
  668. Console.WriteLine("");
  669. Console.WriteLine("");
  670. Console.WriteLine("Required:");
  671. Console.WriteLine("");
  672. Console.WriteLine("-dn BaseDN Base DN to begin the LDAP query.");
  673. Console.WriteLine("");
  674. Console.WriteLine("modification Modification to perform. ");
  675. Console.WriteLine(" See below for details.");
  676. Console.WriteLine("");
  677. Console.WriteLine("Optional:");
  678. Console.WriteLine("");
  679. Console.WriteLine("-p pagesize LDAP Page size to use for query.");
  680. Console.WriteLine("");
  681. Console.WriteLine("-s Denotes a subtree search ");
  682. Console.WriteLine(" (If -s is not specified, search ");
  683. Console.WriteLine(" defaults to onelevel).");
  684. Console.WriteLine("");
  685. Console.WriteLine("-server servername Denotes the server to make the changes ");
  686. Console.WriteLine(" to (If -server is not specified, ");
  687. Console.WriteLine(" changes are made locally if on a DC. ");
  688. Console.WriteLine(" If on a member, DNS is used to ");
  689. Console.WriteLine(" find a DC).");
  690. Console.WriteLine("");
  691. Console.WriteLine("-f LDAPFilter A Valid LDAP filter to use when ");
  692. Console.WriteLine(" enumerating objects (If -f is not ");
  693. Console.WriteLine(" specified, (objectClass=user) is");
  694. Console.WriteLine(" the default filter).");
  695. Console.WriteLine("");
  696. Console.WriteLine("");
  697. Console.WriteLine("Modification Switches:");
  698. Console.WriteLine("");
  699. Console.WriteLine("");
  700. Console.WriteLine("NOTE: Using the word \"null\" (without quotes) as an attribute value will ");
  701. Console.WriteLine(" clear the attribute.");
  702. Console.WriteLine("");
  703. Console.WriteLine("");
  704. Console.WriteLine("============================");
  705. Console.WriteLine("|Terminal Server Attributes|");
  706. Console.WriteLine("============================");
  707. Console.WriteLine("");
  708. Console.WriteLine("Windows 2003 or later is required to modify Terminal Server attributes.");
  709. Console.WriteLine("");
  710. Console.WriteLine("-tsprofilepath ProfilePath Sets the users Terminal Server ");
  711. Console.WriteLine(" Profile path to the specified value.");
  712. Console.WriteLine("");
  713. Console.WriteLine("-tshomefolderpath FolderPath Sets the users Terminal Server home ");
  714. Console.WriteLine(" folder path to the specified value.");
  715. Console.WriteLine("");
  716. Console.WriteLine("-tsnetworkfolderpath driveLetter FolderPath ");
  717. Console.WriteLine(" Sets the users Terminal Server home");
  718. Console.WriteLine(" folder path to a network share.");
  719. Console.WriteLine(" driveLetter should be the drive that");
  720. Console.WriteLine(" FolderPath will be mapped to.");
  721. Console.WriteLine("");
  722. Console.WriteLine("-tsenable Enables the user for Terminal Server.");
  723. Console.WriteLine("");
  724. Console.WriteLine("-tsdisable Disables the user from using Terminal");
  725. Console.WriteLine(" Server.");
  726. Console.WriteLine("");
  727. Console.WriteLine("-enableremote -required -interact Enables Remote Control for the user.");
  728. Console.WriteLine(" The -required and -interact switches");
  729. Console.WriteLine(" are optional. If required is used,");
  730. Console.WriteLine(" \"Require Users Permission\" will be");
  731. Console.WriteLine(" checked. If -interact is specified, ");
  732. Console.WriteLine(" then \"Interact With The Session\" will");
  733. Console.WriteLine(" be checked.");
  734. Console.WriteLine("");
  735. Console.WriteLine("-disableremote Disables Remote Control for the user.");
  736. Console.WriteLine("");
  737. Console.WriteLine("-tsstartingprogram program Sets the program to start when the user");
  738. Console.WriteLine(" logs on to Terminal Server. ");
  739. Console.WriteLine("");
  740. Console.WriteLine("-tsstartin location Sets the location for the users startup");
  741. Console.WriteLine(" program to start in.");
  742. Console.WriteLine("");
  743. Console.WriteLine("-maxdisconnectedsession minutes");
  744. Console.WriteLine(" Sets the maximum disconnected session");
  745. Console.WriteLine(" time for the user in minutes. Setting");
  746. Console.WriteLine(" to 0 minutes indicates an unlimited");
  747. Console.WriteLine(" time.");
  748. Console.WriteLine("");
  749. Console.WriteLine("-maxconnectiontime minutes Sets the maximum connection time for ");
  750. Console.WriteLine(" the user in minutes. Setting to 0");
  751. Console.WriteLine(" indicates an unlimited time.");
  752. Console.WriteLine("");
  753. Console.WriteLine("-maxidletime minutes Sets the maximum idle time for the");
  754. Console.WriteLine(" user in minutes. Setting to 0 ");
  755. Console.WriteLine(" indicates an unlimited time. ");
  756. Console.WriteLine("");
  757. Console.WriteLine("-sessionlimitaction disconnect|end Specifies the action to take when ");
  758. Console.WriteLine(" a sessions limit has been reached.");
  759. Console.WriteLine(" Specify either disconnect (disconnect");
  760. Console.WriteLine(" the session) or end (end the session).");
  761. Console.WriteLine("");
  762. Console.WriteLine("-allowreconnect any|originating Specifies whether or not to allow a");
  763. Console.WriteLine(" reconnect from anywhere (any) or just");
  764. Console.WriteLine(" the originating client (originating).");
  765. Console.WriteLine("");
  766. Console.WriteLine("-tsconnectclientdrives yes|no Specifies whether or not to connect");
  767. Console.WriteLine(" client drives upon logon to a Terminal");
  768. Console.WriteLine(" Server session.");
  769. Console.WriteLine("");
  770. Console.WriteLine("-tsconnectclientprinters yes|no Specifies whether or not to connect");
  771. Console.WriteLine(" client printers upon logon to a ");
  772. Console.WriteLine(" Terminal Server session.");
  773. Console.WriteLine("");
  774. Console.WriteLine("-tsdefaulttomainprinter yes|no Specifies whether or not to default");
  775. Console.WriteLine(" to the main client printer.");
  776. Console.WriteLine("");
  777. Console.WriteLine("");
  778. Console.WriteLine("=============================");
  779. Console.WriteLine("|Exchange Related Attributes|");
  780. Console.WriteLine("=============================");
  781. Console.WriteLine("");
  782. Console.WriteLine("-killmail Removes Exchange Attributes.");
  783. Console.WriteLine("");
  784. Console.WriteLine("-includeinrecipientpolicy Checks \"Automatically Update E-mail");
  785. Console.WriteLine(" Addresses Based on Recipient Policy\"");
  786. Console.WriteLine(" Check box.");
  787. Console.WriteLine("");
  788. Console.WriteLine("-excludefromrecipientpolicy Unchecks \"Automatically Update E-mail");
  789. Console.WriteLine(" Addresses Based on Recipient Policy\"");
  790. Console.WriteLine(" Check box.");
  791. Console.WriteLine("");
  792. Console.WriteLine("-hidefromaddresslists Hides the user from all Address Lists.");
  793. Console.WriteLine("");
  794. Console.WriteLine("-showinaddresslists Shows the user in address lists.");
  795. Console.WriteLine("");
  796. Console.WriteLine("-includeinmailboxmanager Includes the user in mailbox manager");
  797. Console.WriteLine(" policies.");
  798. Console.WriteLine("");
  799. Console.WriteLine("-excludefrommailboxmanager Excludes the user from mailbox manager");
  800. Console.WriteLine(" policies.");
  801. Console.WriteLine("");
  802. Console.WriteLine("-enablehttp Enables HTTP for the user.");
  803. Console.WriteLine("");
  804. Console.WriteLine("-disablehttp Disables HTTP for the user.");
  805. Console.WriteLine("");
  806. Console.WriteLine("-enablepop3 Enables POP3 for the user.");
  807. Console.WriteLine("");
  808. Console.WriteLine("-disablepop3 Disables POP3 for the user.");
  809. Console.WriteLine("");
  810. Console.WriteLine("-enableimap4 Enables IMAP4 for the user.");
  811. Console.WriteLine("");
  812. Console.WriteLine("-disableimap4 Disables IMAP4 for the user.");
  813. Console.WriteLine("");
  814. Console.WriteLine("The three MAPI settings below require that the users mailbox");
  815. Console.WriteLine("is homed on an Exchange 2003 SP2 or later server.");
  816. Console.WriteLine("");
  817. Console.WriteLine("-enablemapi Enables MAPI access for the user.");
  818. Console.WriteLine("");
  819. Console.WriteLine("-disablemapi Disables MAPI access for the user.");
  820. Console.WriteLine("");
  821. Console.WriteLine("-enablecachedmapi Enables MAPI access for users in");
  822. Console.WriteLine(" cached mode only.");
  823. Console.WriteLine("");
  824. Console.WriteLine("-addsmtp address -setasprimary -updatemail");
  825. Console.WriteLine(" Adds an SMTP address to the user.");
  826. Console.WriteLine(" Address will need to be in the form");
  827. Console.WriteLine(" of variable@domain.com (Information");
  828. Console.WriteLine(" on variable usage can be found below");
  829. Console.WriteLine(" under \"Variables\"). Specify the ");
  830. Console.WriteLine(" optional setasprimary switch to set ");
  831. Console.WriteLine(" the address as primary (default ");
  832. Console.WriteLine(" is secondary). Use the -updatemail");
  833. Console.WriteLine(" switch to also set the E-mail address");
  834. Console.WriteLine(" on the ADU&C General tab.");
  835. Console.WriteLine("");
  836. Console.WriteLine("-removeaddress address Removes any address that matches the");
  837. Console.WriteLine(" specified filter. Wild cards are");
  838. Console.WriteLine(" allowed. Examples would be:\n");
  839. Console.WriteLine(" smtp:*@domain.com");
  840. Console.WriteLine(" smtp:*@doma??.com\n");
  841. Console.WriteLine(" Normal * and ? wildcard matching");
  842. Console.WriteLine(" rules apply. Please note that this");
  843. Console.WriteLine(" can be used to remove any match found");
  844. Console.WriteLine(" in the users Proxy Addresses list,");
  845. Console.WriteLine(" not just SMTP addresses. Matches are");
  846. Console.WriteLine(" case-insensitive.");
  847. Console.WriteLine("");
  848. Console.WriteLine("");
  849. Console.WriteLine("----Mailbox Rights----");
  850. Console.WriteLine("");
  851. Console.WriteLine("-setmailboxrights Sets msExchMailboxSecurityDescriptor.");
  852. Console.WriteLine(" KB 324353");
  853. Console.WriteLine("");
  854. Console.WriteLine("-fixsendas Grants Send-As rights to users with");
  855. Console.WriteLine(" Full Mailbox Access and Read.");
  856. Console.WriteLine(" KB 327274");
  857. Console.WriteLine("");
  858. Console.WriteLine("-removefixsendas Removes Send-As rights from users");
  859. Console.WriteLine(" with Full Mailbox Access and Read.");
  860. Console.WriteLine(" Undo for KB 327274");
  861. Console.WriteLine("");
  862. Console.WriteLine("-grantselfaea Grants Associated External Account");
  863. Console.WriteLine(" privileges to SELF. KB 278966");
  864. Console.WriteLine("");
  865. Console.WriteLine("-removeaeafromself Removes Associated External Account");
  866. Console.WriteLine(" from SELF. Undo for KB 278966");
  867. Console.WriteLine("");
  868. Console.WriteLine("-grantselffullandread Grants Full Mailbox Access and Read");
  869. Console.WriteLine(" to SELF. KB 304935");
  870. Console.WriteLine("");
  871. Console.WriteLine("-removefullandread Removes Full Mailbox Access and Read");
  872. Console.WriteLine(" from SELF. Undo for KB 304935");
  873. Console.WriteLine("");
  874. Console.WriteLine("-dumpmailboxrights Dumps all permissions in Mailbox Rights");
  875. Console.WriteLine(" to a file called mbxrights.xml.");
  876. Console.WriteLine("");
  877. Console.WriteLine("-importmailboxrights overwrite|append");
  878. Console.WriteLine(" Imports mailbox rights from the");
  879. Console.WriteLine(" mbxrights.xml created by the");
  880. Console.WriteLine(" -dumpmailboxrights switch. When using");
  881. Console.WriteLine(" this switch, the -dn switch is not");
  882. Console.WriteLine(" required. Overwrite will remove all");
  883. Console.WriteLine(" non-inherited ACE's before importing,");
  884. Console.WriteLine(" append will not. This switch only");
  885. Console.WriteLine(" imports non-inherited mailbox");
  886. Console.WriteLine(" rights.");
  887. Console.WriteLine("");
  888. Console.WriteLine("-addtomailboxrights DOMAIN\\USER ACCESS_MASK -deny (Optional)");
  889. Console.WriteLine(" Adds an account to mailbox rights with");
  890. Console.WriteLine(" the specified permissions masks. The ");
  891. Console.WriteLine(" optional -deny switch specfies a deny");
  892. Console.WriteLine(" entry, default is an allow entry.");
  893. Console.WriteLine(" Valid Access Masks:");
  894. Console.WriteLine("");
  895. Console.WriteLine(" ACE_MB_FULL_ACCESS");
  896. Console.WriteLine(" ACE_MB_DELETE_MB_STORAGE");
  897. Console.WriteLine(" ACE_MB_READ_PERMISSIONS");
  898. Console.WriteLine(" ACE_MB_CHANGE_PERMISSION");
  899. Console.WriteLine(" ACE_MB_TAKE_OWNERSHIP");
  900. Console.WriteLine("");
  901. Console.WriteLine("-removefrommailboxrights DOMAIN\\USER ACCESS_MASK -deny (optional)");
  902. Console.WriteLine(" Removes the specified mask from");
  903. Console.WriteLine(" DOMAIN\\USER in mailbox rights. The");
  904. Console.WriteLine(" -deny switch specifies a deny entry,");
  905. Console.WriteLine(" default is an allow entry.");
  906. Console.WriteLine(" Valid Access Masks:");
  907. Console.WriteLine("");
  908. Console.WriteLine(" ACE_MB_FULL_ACCESS");
  909. Console.WriteLine(" ACE_MB_DELETE_MB_STORAGE");
  910. Console.WriteLine(" ACE_MB_READ_PERMISSIONS");
  911. Console.WriteLine(" ACE_MB_CHANGE_PERMISSION");
  912. Console.WriteLine(" ACE_MB_TAKE_OWNERSHIP");
  913. Console.WriteLine(" ALL");
  914. Console.WriteLine("");
  915. Console.WriteLine(" The ALL Mask will remove all permissions");
  916. Console.WriteLine(" for the specified user.");
  917. Console.WriteLine("");
  918. Console.WriteLine("");
  919. Console.WriteLine("=======================");
  920. Console.WriteLine("|User Account Settings|");
  921. Console.WriteLine("=======================");
  922. Console.WriteLine("");
  923. Console.WriteLine("-enableaccount Enables the user account.");
  924. Console.WriteLine("");
  925. Console.WriteLine("-disableaccount Disables the user account.");
  926. Console.WriteLine("");
  927. Console.WriteLine("-passwordnotrequired yes|no Specifies whether to set the password");
  928. Console.WriteLine(" not required option.");
  929. Console.WriteLine("");
  930. Console.WriteLine("-passwordneverexpires yes|no Specifies whether to check or uncheck");
  931. Console.WriteLine(" the \"Password Never Expires\" box.");
  932. Console.WriteLine("");
  933. Console.WriteLine("-mustchangepassword yes|no Specifies whether to check or uncheck");
  934. Console.WriteLine(" the \"User Must Change Password at Next");
  935. Console.WriteLine(" Logon\" box.");
  936. Console.WriteLine("");
  937. Console.WriteLine("-cannotchangepassword yes|no Specifies whether to check or uncheck");
  938. Console.WriteLine(" the \"User Cannot Change Password\" box.");
  939. Console.WriteLine("");
  940. Console.WriteLine("-usereversibleencryption yes|no Specifies whether to check or uncheck");
  941. Console.WriteLine(" the \"Store Password Using Reversible ");
  942. Console.WriteLine(" Encryption\" box.");
  943. Console.WriteLine("");
  944. Console.WriteLine("-smartcardrequired yes|no Specifies whether to check or uncheck");
  945. Console.WriteLine(" the \"Smart Card is Required for ");
  946. Console.WriteLine(" Interactive Logon\" box.");
  947. Console.WriteLine("");
  948. Console.WriteLine("-cannotbedelegated yes|no Specifies whether to check or uncheck");
  949. Console.WriteLine(" the \"Account is Sensitive and Cannot");
  950. Console.WriteLine(" be Delegated\" box.");
  951. Console.WriteLine("");
  952. Console.WriteLine("-usedesencryption yes|no Specifies whether to check or uncheck");
  953. Console.WriteLine(" the \"Use DES Encryption Types for This");
  954. Console.WriteLine(" Account\" box.");
  955. Console.WriteLine("");
  956. Console.WriteLine("-donotrequirekerberospreauth yes|no Specifies whether to check or uncheck");
  957. Console.WriteLine(" the \"Do Not Require Kerberos ");
  958. Console.WriteLine(" Preauthentication\" box.");
  959. Console.WriteLine("");
  960. Console.WriteLine("-addtogroup DNOfGroup Adds the user to the specified group.");
  961. Console.WriteLine("");
  962. Console.WriteLine("-removefromgroup DNOfGroup Removes the user from the specified");
  963. Console.WriteLine(" group.");
  964. Console.WriteLine("");
  965. Console.WriteLine("-allowinheritable yes|no Specifies whether to check or uncheck");
  966. Console.WriteLine(" the \"Allow inheritable permissions to");
  967. Console.WriteLine(" propagate to this object\" box.");
  968. Console.WriteLine("");
  969. Console.WriteLine("-modrdn NewRDN Changes the users Relative Distinguished");
  970. Console.WriteLine(" Name (CN). Variable usage is required.");
  971. Console.WriteLine(" To change an RDN to LastName, FirstName");
  972. Console.WriteLine(" use the following syntax:");
  973. Console.WriteLine(" -modrdn \"%'sn'%, %'givenName'%\"");
  974. Console.WriteLine("");
  975. Console.WriteLine("===================");
  976. Console.WriteLine("|Custom Attributes|");
  977. Console.WriteLine("===================");
  978. Console.WriteLine("");
  979. Console.WriteLine("The -custom switch allows you to name the attribute you wish to modify. This");
  980. Console.WriteLine("operation is only supported against attributes of the following type:");
  981. Console.WriteLine("");
  982. Console.WriteLine("Boolean");
  983. Console.WriteLine("Case Insensitive String");
  984. Console.WriteLine("Distinguished Name");
  985. Console.WriteLine("DN Binary");
  986. Console.WriteLine("IA5-String");
  987. Console.WriteLine("Integer");
  988. Console.WriteLine("Numerical String");
  989. Console.WriteLine("Unicode String");
  990. Console.WriteLine("");
  991. Console.WriteLine("Syntax: ");
  992. Console.WriteLine("[-custom attributeName attributeValue -multi|-remove]");
  993. Console.WriteLine("");
  994. Console.WriteLine("attributeName The name of the attribute you wish");
  995. Console.WriteLine(" to modify.");
  996. Console.WriteLine("");
  997. Console.WriteLine("attributeValue The value to give the attribute.");
  998. Console.WriteLine("");
  999. Console.WriteLine("-multi (optional) Specifies a multi-valued append. If");
  1000. Console.WriteLine(" the attribute being modified is multi-");
  1001. Console.WriteLine(" valued this switch needs to be used. ");
  1002. Console.WriteLine(" Otherwise, the value will be ");
  1003. Console.WriteLine(" overwritten, not appended.");
  1004. Console.WriteLine("");
  1005. Console.WriteLine("-remove (optional) Specifies a multi-valued remove. If");
  1006. Console.WriteLine(" the attribute being modified is multi-");
  1007. Console.WriteLine(" valued and -remove is used, then only");
  1008. Console.WriteLine(" the specified value will get removed.");
  1009. Console.WriteLine("");
  1010. Console.WriteLine("Example for setting description attribute:");
  1011. Console.WriteLine("");
  1012. Console.WriteLine("-custom description \"IT Department\"");
  1013. Console.WriteLine("");
  1014. Console.WriteLine("");
  1015. Console.WriteLine("==========");
  1016. Console.WriteLine("|Variables|");
  1017. Console.WriteLine("==========");
  1018. Console.WriteLine("");
  1019. Console.WriteLine("Variable usage is allowed when building attributes. Variables can be based ");
  1020. Console.WriteLine("off of almost any current Active Directory attribute, as long as it has a ");
  1021. Console.WriteLine("value. Variables are seperated from literal values using the % sign.");
  1022. Console.WriteLine("Variables must also be enclosed in a single tick (').");
  1023. Console.WriteLine("");
  1024. Console.WriteLine("This example shows how to set homeDirectory to the path c:\\test\\username, ");
  1025. Console.WriteLine("where username is the users sAMAccountName:");
  1026. Console.WriteLine("");
  1027. Console.WriteLine("-custom homeDirectory c:\\test\\%'sAMAccountName'%");
  1028. Console.WriteLine("");
  1029. Console.WriteLine("It is also possible to pull only a specified number of characters from the ");
  1030. Console.WriteLine("attribute as well. Just specify the number of characters you want to use");
  1031. Console.WriteLine("after the %, and before the \"'\". The following example shows how to add ");
  1032. Console.WriteLine("an SMTP address of FirstInitial.LastName@domain.com:");
  1033. Console.WriteLine("");
  1034. Console.WriteLine("-addsmtp %1'givenName'%.%'sn'%@domain.com");
  1035. Console.WriteLine("");
  1036. Console.WriteLine("If a % or ' is needed as a literal value, simply use the forward slash (/)");
  1037. Console.WriteLine("as an escape character:");
  1038. Console.WriteLine("");
  1039. Console.WriteLine("Example:");
  1040. Console.WriteLine("This is a percent sign: /%");
  1041. Console.WriteLine("");
  1042. Console.WriteLine("The above line will end up being: This is a percent sign: %");
  1043. Console.WriteLine("");
  1044. Console.WriteLine("There may be times where you need a literal forward slash before the");
  1045. Console.WriteLine("percentage or single tick characters, usually when the forward slash");
  1046. Console.WriteLine("needs to be followed by a variable. The syntax for this is //% or //'");
  1047. Console.WriteLine("An example would be adding an MS Mail address:");
  1048. Console.WriteLine("");
  1049. Console.WriteLine("ms:PO/SERVER//%'mailNickName'");
  1050. Console.WriteLine("");
  1051. Console.WriteLine("===========");
  1052. Console.WriteLine("|Undo Mode|");
  1053. Console.WriteLine("===========");
  1054. Console.WriteLine("");
  1055. Console.WriteLine("Changes made with ADModify can be undone, as long as the xml log file that");
  1056. Console.WriteLine("logged the changes still exists. These log files are typically located in");
  1057. Console.WriteLine("the same folder as the admodify executable.");
  1058. Console.WriteLine("");
  1059. Console.WriteLine("Syntax:");
  1060. Console.WriteLine("[-undo logfilename -server servername]");
  1061. Console.WriteLine("");
  1062. Console.WriteLine("-undo logfilename Specifes the log file that contains the");
  1063. Console.WriteLine(" changes to be undone.");
  1064. Console.WriteLine("");
  1065. Console.WriteLine("-server servername (optional) Specifies the DC to write the changes");
  1066. Console.WriteLine(" to. If left blank changes are written");
  1067. Console.WriteLine(" locally if the local machine is a DC.");
  1068. Console.WriteLine(" If not, DNS is used to find one.");
  1069. Console.WriteLine("");
  1070. Console.WriteLine("For information on users that were skipped during an undo process, refer");
  1071. Console.WriteLine("to the undo.log file.");
  1072. Console.WriteLine("");
  1073. Console.WriteLine("For more information on sample usage, please refer to the ADModify help.");
  1074. Console.WriteLine("");
  1075. Console.WriteLine("");
  1076. }
  1077. /// <summary>
  1078. /// ADModifyMain::Main
  1079. ///
  1080. /// Accepts:
  1081. /// args - command line arguments passed by the user
  1082. /// Returns:
  1083. /// nothing
  1084. ///
  1085. /// Here we accept all command line arguments and set the global variables for these
  1086. /// arguments accordingly. Control is then given to the GetDN function.
  1087. /// </summary>
  1088. [STAThread]
  1089. static void Main(string[] args)
  1090. {
  1091. LogFile log = new LogFile();
  1092. DateTime endTime;
  1093. TimeSpan finalCount;
  1094. string RawDateTime = System.DateTime.Now.ToString();
  1095. RawDateTime = RawDateTime.Replace(" ","").Replace("/","").Replace(":","");
  1096. string logFileName = RawDateTime + ".xml";
  1097. XmlTextWriter logWriter = new XmlTextWriter(logFileName, null);
  1098. logWriter.WriteStartDocument(false);
  1099. logWriter.WriteDocType("LogFile", null, null, null);
  1100. logWriter.WriteStartElement("XmlRoot", logFileName);
  1101. DateTime startTime = System.DateTime.Now;
  1102. bool haveDN = false; //flip this bit when we have a base DN passed
  1103. int numberargs = args.Length;
  1104. string LDAPFilter = "(objectClass=user)"; //default to this in case a filter is not specified
  1105. bool subtree = false; //default to a onelevel search
  1106. bool bitflipped = false; //if any valid attribute switch is given we flip this bit
  1107. string SearchBase = "blank";
  1108. //loop through args and set the necesarry information
  1109. for(int i=0; i < numberargs; i++)
  1110. {
  1111. switch(args[i].ToLower())
  1112. {
  1113. case "/?":
  1114. case "-?":
  1115. bitflipped = true;
  1116. GiveCommandArgs();
  1117. return;
  1118. case "-server":
  1119. try
  1120. {
  1121. servername = args[i+1];
  1122. i++;
  1123. }
  1124. catch(System.IndexOutOfRangeException)
  1125. {
  1126. Console.WriteLine("Please enter a server name after the -servername switch.");
  1127. return;
  1128. }
  1129. break;
  1130. case "-f":
  1131. try
  1132. {
  1133. LDAPFilter = args[i+1];
  1134. i++;
  1135. }
  1136. catch(System.IndexOutOfRangeException)
  1137. {
  1138. Console.WriteLine("Please enter an LDAP filter after the -filter switch.");
  1139. return;
  1140. }
  1141. break;
  1142. case "-p":
  1143. try
  1144. {
  1145. pageSize = Convert.ToInt32(args[i+1],10);
  1146. if(pageSize>1000 || pageSize==0)
  1147. {
  1148. Console.WriteLine("Please enter a page size between 1 and 1000.");
  1149. return;
  1150. }
  1151. i++;
  1152. }
  1153. catch(System.IndexOutOfRangeException)
  1154. {
  1155. Console.WriteLine("Please enter a page size after the -p switch.");
  1156. return;
  1157. }
  1158. break;
  1159. case "-s":
  1160. subtree = true;
  1161. break;
  1162. case "-dn":
  1163. try
  1164. {
  1165. haveDN=true;
  1166. SearchBase = args[i+1];
  1167. i++;
  1168. }
  1169. catch(System.IndexOutOfRangeException)
  1170. {
  1171. Console.WriteLine("Please enter a valid dn after the -dn switch.");
  1172. return;
  1173. }
  1174. break;
  1175. //////////////////////////////////////////////////
  1176. /// Terminal Server Attributes ///
  1177. //////////////////////////////////////////////////
  1178. //set TS profile path
  1179. case "-tsprofilepath":
  1180. try
  1181. {
  1182. TSProfilePath = args[i+1];
  1183. bitflipped = true;
  1184. i++;
  1185. break;
  1186. }
  1187. catch(System.IndexOutOfRangeException)
  1188. {
  1189. Console.WriteLine("Please enter the new profile value after the -tsprofilepath path swtich.");
  1190. return;
  1191. }
  1192. catch(System.Exception caught)
  1193. {
  1194. Console.WriteLine(caught.Message);
  1195. return;
  1196. }
  1197. //set local TS home folder path
  1198. case "-tshomefolderpath":
  1199. try
  1200. {
  1201. TSFolderPath = args[i+1];
  1202. bitflipped = true;
  1203. i++;
  1204. break;
  1205. }
  1206. catch(System.IndexOutOfRangeException)
  1207. {
  1208. Console.WriteLine("Please enter the new home folder value after the -tshomefolderpath switch.");
  1209. return;
  1210. }
  1211. catch(System.Exception caught)
  1212. {
  1213. Console.WriteLine(caught.Message);
  1214. return;
  1215. }
  1216. //set TS home folder path to network drive
  1217. case "-tsnetworkfolderpath":
  1218. try
  1219. {
  1220. TSHomeDrive = args[i+1];
  1221. if(TSHomeDrive=="null")
  1222. {
  1223. bitflipped = true;
  1224. TSFolderPath = TSHomeDrive;
  1225. i=i+2;
  1226. break;
  1227. }
  1228. if(!TSHomeDrive.EndsWith(":"))
  1229. {
  1230. Console.WriteLine("Drive Letter must end in a : ");
  1231. return;
  1232. }
  1233. TSFolderPath = args[i+2];
  1234. bitflipped = true;
  1235. i=i+2;
  1236. break;
  1237. }
  1238. catch(System.IndexOutOfRangeException)
  1239. {
  1240. Console.WriteLine("Please enter a drive letter followed by a network path.");
  1241. return;
  1242. }
  1243. catch(System.Exception caught)
  1244. {
  1245. Console.WriteLine(caught.Message);
  1246. return;
  1247. }
  1248. //enable TS access
  1249. case "-tsenable":
  1250. try
  1251. {
  1252. TSEnable = true;
  1253. bitflipped = true;
  1254. }
  1255. catch(System.Exception caught)
  1256. {
  1257. Console.WriteLine(caught.Message);
  1258. }
  1259. break;
  1260. //disable TS access
  1261. case "-tsdisable":
  1262. try
  1263. {
  1264. TSDisable = true;
  1265. bitflipped = true;
  1266. }
  1267. catch(System.Exception caught)
  1268. {
  1269. Console.WriteLine(caught.Message);
  1270. }
  1271. break;
  1272. //enable remote control, utilizes the -required and -interact switches
  1273. case "-enableremote":
  1274. try
  1275. {
  1276. RemoteEnable = true;
  1277. bitflipped = true;
  1278. }
  1279. catch(System.Exception caught)
  1280. {
  1281. Console.WriteLine(caught.Message);
  1282. }
  1283. break;
  1284. //used with the -enableremote switch
  1285. case "-required":
  1286. try
  1287. {
  1288. RequirePermission = true;
  1289. }
  1290. catch(System.Exception caught)
  1291. {
  1292. Console.WriteLine(caught.Message);
  1293. }
  1294. break;
  1295. //used with the -enableremote switch
  1296. case "-interact":
  1297. try
  1298. {
  1299. InteractWithSession = true;
  1300. }
  1301. catch(System.Exception caught)
  1302. {
  1303. Console.WriteLine(caught.Message);
  1304. }
  1305. break;
  1306. //disable remote control
  1307. case "-disableremote":
  1308. try
  1309. {
  1310. RemoteDisable = true;
  1311. bitflipped = true;
  1312. }
  1313. catch(System.Exception caught)
  1314. {
  1315. Console.WriteLine(caught.Message);
  1316. }
  1317. break;
  1318. //set TS startup program
  1319. case "-tsstartingprogram":
  1320. try
  1321. {
  1322. program = args[i+1];
  1323. bitflipped = true;
  1324. i++;
  1325. }
  1326. catch(System.IndexOutOfRangeException)
  1327. {
  1328. Console.WriteLine("Please specify a program to run after the -tsstartingprogram switch.");
  1329. return;
  1330. }
  1331. catch(System.Exception caught)
  1332. {
  1333. Console.WriteLine(caught.Message);
  1334. }
  1335. break;
  1336. //set startup location for TS startup program
  1337. case "-tsstartin":
  1338. try
  1339. {
  1340. startIn = args[i+1];
  1341. bitflipped = true;
  1342. i++;
  1343. }
  1344. catch(System.IndexOutOfRangeException)
  1345. {
  1346. Console.WriteLine("Please specify a startup location after the -tsstartin switch.");
  1347. return;
  1348. }
  1349. catch(System.Exception caught)
  1350. {
  1351. Console.WriteLine(caught.Message);
  1352. }
  1353. break;
  1354. //set disconnected session time
  1355. case "-maxdisconnectedsession":
  1356. try
  1357. {
  1358. SetDisconnectTime = true;
  1359. DisconnectTime = Convert.ToInt32(args[i+1], 10);
  1360. bitflipped = true;
  1361. i++;
  1362. }
  1363. catch(System.IndexOutOfRangeException)
  1364. {
  1365. Console.WriteLine("Please specify the number of minutes");
  1366. return;
  1367. }
  1368. catch(System.Exception caught)
  1369. {
  1370. Console.WriteLine(caught.Message);
  1371. }
  1372. break;
  1373. //set maximum session time
  1374. case "-maxconnectiontime":
  1375. try
  1376. {
  1377. SetMaxConnectionTime = true;
  1378. MaxConnectionTime = Convert.ToInt32(args[i+1], 10);
  1379. bitflipped = true;
  1380. i++;
  1381. }
  1382. catch(System.IndexOutOfRangeException)
  1383. {
  1384. Console.WriteLine("Please specify the number of minutes");
  1385. return;
  1386. }
  1387. catch(System.Exception caught)
  1388. {
  1389. Console.WriteLine(caught.Message);
  1390. }
  1391. break;
  1392. //set idle time limit
  1393. case "-maxidletime":
  1394. try
  1395. {
  1396. SetMaxIdleTime = true;
  1397. MaxIdleTime = Convert.ToInt32(args[i+1], 10);
  1398. bitflipped = true;
  1399. i++;
  1400. }
  1401. catch(System.IndexOutOfRangeException)
  1402. {
  1403. Console.WriteLine("Please specify the number of minutes");
  1404. return;
  1405. }
  1406. catch(System.Exception caught)
  1407. {
  1408. Console.WriteLine(caught.Message);
  1409. }
  1410. break;
  1411. //seesion limit or broken connection action
  1412. case "-sessionlimitaction":
  1413. try
  1414. {
  1415. SetEndSession = true;
  1416. bitflipped = true;
  1417. if(args[i+1]=="disconnect")
  1418. {
  1419. //do nothing, already set to false
  1420. }
  1421. else if(args[i+1]=="end")
  1422. {
  1423. EndSession = true;
  1424. }
  1425. else
  1426. {
  1427. Console.WriteLine(args[i+1] + " is not a valid argument. Please specify either disconnect or end.");
  1428. return;
  1429. }
  1430. i++;
  1431. break;
  1432. }
  1433. catch(System.IndexOutOfRangeException)
  1434. {
  1435. Console.WriteLine("Please specify either disconnect or end after the -sessionlimitaction switch.");
  1436. return;
  1437. }
  1438. catch(System.Exception caught)
  1439. {
  1440. Console.WriteLine(caught.Message);
  1441. return;
  1442. }
  1443. //TS reconnect action
  1444. case "-allowreconnect":
  1445. try
  1446. {
  1447. SetOriginatingOnly = true;
  1448. bitflipped = true;
  1449. if(args[i+1]=="any")
  1450. {
  1451. //do nothing, already set to false
  1452. }
  1453. else if(args[i+1]=="originating")
  1454. {
  1455. OriginatingOnly = true;
  1456. }
  1457. else
  1458. {
  1459. Console.WriteLine(args[i+1] + " is not a valid argument. Please specify either any or originating.");
  1460. return;
  1461. }
  1462. i++;
  1463. break;
  1464. }
  1465. catch(System.IndexOutOfRangeException)
  1466. {
  1467. Console.WriteLine("Please specify either any or originating after the -allowreconnect switch.");
  1468. return;
  1469. }
  1470. catch(System.Exception caught)
  1471. {
  1472. Console.WriteLine(caught.Message);
  1473. return;
  1474. }
  1475. //TS Connect Client Drives at Logon
  1476. case "-tsconnectclientdrives":
  1477. try
  1478. {
  1479. SetConnectClientDrives = true;
  1480. bitflipped = true;
  1481. if(args[i+1]=="yes")
  1482. {
  1483. ConnectClientDrives = true;
  1484. }
  1485. else if(args[i+1]=="no")
  1486. {
  1487. //do nothing, already set to false
  1488. }
  1489. else
  1490. {
  1491. Console.WriteLine("Please specify either yes or no after the -tsconnectclientdrives switch.");
  1492. return;
  1493. }
  1494. i++;
  1495. break;
  1496. }
  1497. catch(System.IndexOutOfRangeException)
  1498. {
  1499. Console.WriteLine("Please specify yes or no after the -tsconnectclientdrives switch.");
  1500. return;
  1501. }
  1502. catch(System.Exception caught)
  1503. {
  1504. Console.WriteLine(caught.Message);
  1505. return;
  1506. }
  1507. //TS Connect Client Printers at Logon
  1508. case "-tsconnectclientprinters":
  1509. try
  1510. {
  1511. SetConnectClientPrinters = true;
  1512. bitflipped = true;
  1513. if(args[i+1]=="yes")
  1514. {
  1515. ConnectClientPrinters = true;
  1516. }
  1517. else if(args[i+1]=="no")
  1518. {
  1519. //do nothing, already set to false
  1520. }
  1521. else
  1522. {
  1523. Console.WriteLine("Please specify either yes or no after the -tsconnectclientprinters switch.");
  1524. return;
  1525. }
  1526. i++;
  1527. break;
  1528. }
  1529. catch(System.IndexOutOfRangeException)
  1530. {
  1531. Console.WriteLine("Please specify yes or no after the -tsconectclientprinters switch.");
  1532. return;
  1533. }
  1534. catch(System.Exception caught)
  1535. {
  1536. Console.WriteLine(caught.Message);
  1537. return;
  1538. }
  1539. //TS Default to main printer
  1540. case "-tsdefaulttomainprinter":
  1541. try
  1542. {
  1543. SetDefaultToMainPrinter = true;
  1544. bitflipped = true;
  1545. if(args[i+1]=="yes")
  1546. {
  1547. DefaultToMainPrinter = true;
  1548. }
  1549. else if(args[i+1]=="no")
  1550. {
  1551. //do nothing, already set to false
  1552. }
  1553. else
  1554. {
  1555. Console.WriteLine("Please specify either yes or no after the -tsdefaulttomainprinter switch.");
  1556. return;
  1557. }
  1558. i++;
  1559. break;
  1560. }
  1561. catch(System.IndexOutOfRangeException)
  1562. {
  1563. Console.WriteLine("Please specify yes or no after the -tsdefaulttomainprinter switch.");
  1564. return;
  1565. }
  1566. catch(System.Exception caught)
  1567. {
  1568. Console.WriteLine(caught.Message);
  1569. return;
  1570. }
  1571. //////////////////////////////////////////////////
  1572. /// Exchange Related Attributes ///
  1573. //////////////////////////////////////////////////
  1574. ///
  1575. ///killmail Switch
  1576. ///
  1577. case "-killmail":
  1578. try
  1579. {
  1580. killmail = true;
  1581. bitflipped = true;
  1582. }
  1583. catch(System.Exception caught)
  1584. {
  1585. Console.WriteLine(caught.Message);
  1586. return;
  1587. }
  1588. break;
  1589. ///
  1590. ///Include in Recipient Policy Switch
  1591. ///
  1592. case "-includeinrecipientpolicy":
  1593. try
  1594. {
  1595. includeinrecipientpolicy = true;
  1596. bitflipped = true;
  1597. }
  1598. catch(System.Exception caught)
  1599. {
  1600. Console.WriteLine(caught.Message);
  1601. return;
  1602. }
  1603. break;
  1604. ///
  1605. ///Exclude from Recipient Policy Switch
  1606. ///
  1607. case "-excludefromrecipientpolicy":
  1608. try
  1609. {
  1610. excludefromrecipientpolicy = true;
  1611. bitflipped = true;
  1612. }
  1613. catch(System.Exception caught)
  1614. {
  1615. Console.WriteLine(caught.Message);
  1616. return;
  1617. }
  1618. break;
  1619. ///
  1620. ///hide from address lists
  1621. ///
  1622. case "-hidefromaddresslists":
  1623. try
  1624. {
  1625. hidefromaddresslists = true;
  1626. bitflipped = true;
  1627. }
  1628. catch(System.Exception caught)
  1629. {
  1630. Console.WriteLine(caught.Message);
  1631. return;
  1632. }
  1633. break;
  1634. ///
  1635. ///show in address lists
  1636. ///
  1637. case "-showinaddresslists":
  1638. try
  1639. {
  1640. showinaddresslists = true;
  1641. bitflipped = true;
  1642. }
  1643. catch(System.Exception caught)
  1644. {
  1645. Console.WriteLine(caught.Message);
  1646. return;
  1647. }
  1648. break;
  1649. ///
  1650. ///Include in Mailbox Manager Policy Switch
  1651. ///
  1652. case "-includeinmailboxmanager":
  1653. try
  1654. {
  1655. includeinmailboxmanager = true;
  1656. bitflipped = true;
  1657. }
  1658. catch(System.Exception caught)
  1659. {
  1660. Console.WriteLine(caught.Message);
  1661. return;
  1662. }
  1663. break;
  1664. ///
  1665. ///Exclude from Mailbox Manager Policy Switch
  1666. ///
  1667. case "-excludefrommailboxmanager":
  1668. try
  1669. {
  1670. excludefrommailboxmanager = true;
  1671. bitflipped = true;
  1672. }
  1673. catch(System.Exception caught)
  1674. {
  1675. Console.WriteLine(caught.Message);
  1676. return;
  1677. }
  1678. break;
  1679. ///
  1680. ///Enable HTTP
  1681. ///
  1682. case "-enablehttp":
  1683. try
  1684. {
  1685. enablehttp = true;
  1686. bitflipped = true;
  1687. }
  1688. catch(System.Exception caught)
  1689. {
  1690. Console.WriteLine(caught.Message);
  1691. return;
  1692. }
  1693. break;
  1694. ///
  1695. ///disable HTTP
  1696. ///
  1697. case "-disablehttp":
  1698. try
  1699. {
  1700. disablehttp = true;
  1701. bitflipped = true;
  1702. }
  1703. catch(System.Exception caught)
  1704. {
  1705. Console.WriteLine(caught.Message);
  1706. return;
  1707. }
  1708. break;
  1709. ///
  1710. ///Enable POP3
  1711. ///
  1712. case "-enablepop3":
  1713. try
  1714. {
  1715. enablepop3 = true;
  1716. bitflipped = true;
  1717. }
  1718. catch(System.Exception caught)
  1719. {
  1720. Console.WriteLine(caught.Message);
  1721. return;
  1722. }
  1723. break;
  1724. ///
  1725. ///Disable POP3
  1726. ///
  1727. case "-disablepop3":
  1728. try
  1729. {
  1730. disablepop3 = true;
  1731. bitflipped = true;
  1732. }
  1733. catch(System.Exception caught)
  1734. {
  1735. Console.WriteLine(caught.Message);
  1736. return;
  1737. }
  1738. break;
  1739. ///
  1740. ///Enable IMAP4
  1741. ///
  1742. case "-enableimap4":
  1743. try
  1744. {
  1745. enableimap4 = true;
  1746. bitflipped = true;
  1747. }
  1748. catch(System.Exception caught)
  1749. {
  1750. Console.WriteLine(caught.Message);
  1751. return;
  1752. }
  1753. break;
  1754. ///
  1755. ///Disable IMAP4
  1756. ///
  1757. case "-disableimap4":
  1758. try
  1759. {
  1760. disableimap4 = true;
  1761. bitflipped = true;
  1762. }
  1763. catch(System.Exception caught)
  1764. {
  1765. Console.WriteLine(caught.Message);
  1766. return;
  1767. }
  1768. break;
  1769. ///
  1770. ///Enable MAPI
  1771. ///
  1772. case "-enablemapi":
  1773. try
  1774. {
  1775. enablemapi=true;
  1776. bitflipped=true;
  1777. }
  1778. catch(System.Exception caught)
  1779. {
  1780. Console.WriteLine(caught.Message);
  1781. return;
  1782. }
  1783. break;
  1784. ///
  1785. ///Disable MAPI
  1786. ///
  1787. case "-disablemapi":
  1788. try
  1789. {
  1790. disablemapi=true;
  1791. bitflipped=true;
  1792. }
  1793. catch(System.Exception caught)
  1794. {
  1795. Console.WriteLine(caught.Message);
  1796. return;
  1797. }
  1798. break;
  1799. ///
  1800. ///Enable cached mode MAPI only
  1801. ///
  1802. case "-enablecachedmapi":
  1803. try
  1804. {
  1805. enablecachedmapi=true;
  1806. bitflipped=true;
  1807. }
  1808. catch(System.Exception caught)
  1809. {
  1810. Console.WriteLine(caught.Message);
  1811. return;
  1812. }
  1813. break;
  1814. ///
  1815. ///Add SMTP address switch
  1816. ///
  1817. case "-addsmtp":
  1818. try
  1819. {
  1820. if(args[i+1].StartsWith("@"))
  1821. {
  1822. Console.WriteLine("SMTP Address must begin with a variable, not an @ sign");
  1823. return;
  1824. }
  1825. else
  1826. {
  1827. smtpaddress = args[i+1];
  1828. i++;
  1829. bitflipped=true;
  1830. break;
  1831. }
  1832. }
  1833. catch(System.IndexOutOfRangeException)
  1834. {
  1835. Console.WriteLine("Invalid value entered for E-mail address");
  1836. return;
  1837. }
  1838. catch(System.Exception caught)
  1839. {
  1840. Console.WriteLine(caught.Message);
  1841. return;
  1842. }
  1843. ///
  1844. ///SMTP set as primary switch
  1845. ///
  1846. case "-setasprimary":
  1847. try
  1848. {
  1849. setasprimary = true;
  1850. }
  1851. catch(System.Exception caught)
  1852. {
  1853. Console.WriteLine(caught.Message);
  1854. return;
  1855. }
  1856. break;
  1857. ///
  1858. ///Update mail attribute on general tab
  1859. ///
  1860. case "-updatemail":
  1861. try
  1862. {
  1863. updatemail=true;
  1864. }
  1865. catch(System.Exception caught)
  1866. {
  1867. Console.WriteLine(caught.Message);
  1868. return;
  1869. }
  1870. break;
  1871. ///
  1872. ///Remove address switch
  1873. ///
  1874. case "-removeaddress":
  1875. try
  1876. {
  1877. if(args[i+1]!=null)
  1878. {
  1879. removeaddress = true;
  1880. addresstoremove = args[i+1];
  1881. i++;
  1882. bitflipped = true;
  1883. break;
  1884. }
  1885. else
  1886. {
  1887. Console.WriteLine("Please specify an address string for removal.");
  1888. return;
  1889. }
  1890. }
  1891. catch(System.IndexOutOfRangeException)
  1892. {
  1893. Console.WriteLine("Invalid address string entered.");
  1894. return;
  1895. }
  1896. catch(System.Exception caught)
  1897. {
  1898. Console.WriteLine(caught.Message);
  1899. return;
  1900. }
  1901. ///
  1902. ///Do not remove primary address when removing email addresses
  1903. ///
  1904. case "-keepprimary":
  1905. try
  1906. {
  1907. keepprimary=true;
  1908. }
  1909. catch(System.Exception caught)
  1910. {
  1911. Console.WriteLine(caught.Message);
  1912. return;
  1913. }
  1914. break;
  1915. ///
  1916. ///Add send-as for the specified account
  1917. ///
  1918. ///some bugs so far with this one, it seems to add more than send-as.
  1919. ///disabling this feature until we can determine the cause.
  1920. case "-grantsendas":
  1921. try
  1922. {
  1923. GrantSendAsRights = true;
  1924. bitflipped = true;
  1925. Trustee = args[i+1];
  1926. i++;
  1927. break;
  1928. }
  1929. catch(System.IndexOutOfRangeException)
  1930. {
  1931. Console.WriteLine("Please enter a valid DOMAIN\\user after the -grantsendas switch.");
  1932. return;
  1933. }
  1934. catch(System.Exception caught)
  1935. {
  1936. Console.WriteLine(caught.Message);
  1937. return;
  1938. }
  1939. ///
  1940. ///Set msExchMailboxSecurityDescriptor
  1941. ///
  1942. case "-setmailboxrights":
  1943. try
  1944. {
  1945. SetMailboxRights = true;
  1946. bitflipped = true;
  1947. break;
  1948. }
  1949. catch(System.Exception caught)
  1950. {
  1951. Console.WriteLine(caught.Message);
  1952. return;
  1953. }
  1954. ///
  1955. ///Grand send-as rights to users with full mailbox access and read
  1956. ///
  1957. case "-fixsendas":
  1958. try
  1959. {
  1960. FixSendAs = true;
  1961. bitflipped = true;
  1962. break;
  1963. }
  1964. catch(System.Exception caught)
  1965. {
  1966. Console.WriteLine(caught.Message);
  1967. return;
  1968. }
  1969. ///
  1970. ///Remove Send-As permissions from users with full mailbox access
  1971. ///
  1972. case "-removefixsendas":
  1973. try
  1974. {
  1975. RemoveSendAs = true;
  1976. bitflipped = true;
  1977. break;
  1978. }
  1979. catch(System.Exception caught)
  1980. {
  1981. Console.WriteLine(caught.Message);
  1982. return;
  1983. }
  1984. ///
  1985. ///Grant SELF associated external account privileges
  1986. ///
  1987. case "-grantselfaea":
  1988. try
  1989. {
  1990. GrantSelfAEA = true;
  1991. bitflipped = true;
  1992. break;
  1993. }
  1994. catch(System.Exception caught)
  1995. {
  1996. Console.WriteLine(caught.Message);
  1997. return;
  1998. }
  1999. ///
  2000. ///Remove associated external account from SELF
  2001. ///
  2002. case "-removeaeafromself":
  2003. try
  2004. {
  2005. RemoveAEAFromSelf = true;
  2006. bitflipped = true;
  2007. break;
  2008. }
  2009. catch(System.Exception caught)
  2010. {
  2011. Console.WriteLine(caught.Message);
  2012. return;
  2013. }
  2014. ///
  2015. ///Grant SELF full mailbox access and Read
  2016. ///
  2017. case "-grantselffullandread":
  2018. try
  2019. {
  2020. GrantSelfFullAndRead = true;
  2021. bitflipped = true;
  2022. break;
  2023. }
  2024. catch(System.Exception caught)
  2025. {
  2026. Console.WriteLine(caught.Message);
  2027. return;
  2028. }
  2029. ///
  2030. ///Remove Full Mailbox Access and Read from SELF
  2031. ///
  2032. case "-removefullandread":
  2033. try
  2034. {
  2035. RemoveSelfFullAndRead = true;
  2036. bitflipped = true;
  2037. break;
  2038. }
  2039. catch(System.Exception caught)
  2040. {
  2041. Console.WriteLine(caught.Message);
  2042. return;
  2043. }
  2044. ///
  2045. ///Dump Mailbox Rights to XML file
  2046. ///
  2047. case "-dumpmailboxrights":
  2048. try
  2049. {
  2050. DumpMailboxRights = true;
  2051. bitflipped = true;
  2052. break;
  2053. }
  2054. catch(System.Exception caught)
  2055. {
  2056. Console.WriteLine(caught.Message);
  2057. return;
  2058. }
  2059. ///
  2060. ///Imports mailbox rights from mbxrights.xml
  2061. ///
  2062. case "-importmailboxrights":
  2063. try
  2064. {
  2065. if(args[i+1].ToLower()=="overwrite")
  2066. {
  2067. MailboxRightsOverwrite = true;
  2068. }
  2069. else if(args[i+1].ToLower()=="append")
  2070. {
  2071. //do nothing, already false
  2072. }
  2073. else
  2074. {
  2075. Console.WriteLine("You must enter either overwrite or append after the -importmailboxrights switch.");
  2076. return;
  2077. }
  2078. i+=2;
  2079. ImportMailboxRights = true;
  2080. bitflipped = true;
  2081. break;
  2082. }
  2083. catch(System.IndexOutOfRangeException)
  2084. {
  2085. Console.WriteLine("You must enter either overwrite or append after the -importmailboxrights switch.");
  2086. return;
  2087. }
  2088. catch(System.Exception caught)
  2089. {
  2090. Console.WriteLine(caught.Message);
  2091. return;
  2092. }
  2093. ///
  2094. ///Add permission to mailbox rights
  2095. ///
  2096. case "-addtomailboxrights":
  2097. try
  2098. {
  2099. bitflipped = true;
  2100. ModifyMailboxRights = true;
  2101. Trustee = args[i+1].ToUpper();
  2102. Permission = args[i+2].ToUpper();
  2103. if(Permission!="ACE_MB_FULL_ACCESS" && Permission!="ACE_MB_ASSOC_EXT_ACCT" && Permission!="ACE_MB_DELETE_MB_STORAGE" && Permission!="ACE_MB_READ_PERMISSIONS" && Permission!="ACE_MB_CHANGE_PERMISSION" && Permission!="ACE_MB_TAKE_OWNERSHIP" && Permission!="ALL")
  2104. {
  2105. Console.WriteLine("You must enter one of the following as a permissions mask:");
  2106. Console.WriteLine("\nACE_MB_FULL_ACCESS\nACE_MB_ASSOC_EXT_ACCT\nACE_MB_DELETE_MB_STORAGE\nACE_MB_READ_PERMISSIONS\nACE_MB_CHANGE_PERMISSION\nACE_MB_TAKE_OWNERSHIP\nALL\n");
  2107. Console.WriteLine("\nTo set a deny, use the -deny switch.");
  2108. return;
  2109. }
  2110. i+=2;
  2111. break;
  2112. }
  2113. catch(System.IndexOutOfRangeException)
  2114. {
  2115. Console.WriteLine("You must enter an account to grant permissions to, followed by the permission you wish to grant.");
  2116. Console.WriteLine("The account must be in DOMAIN\\User format, and permission must be one of the following:");
  2117. Console.WriteLine("\nACE_MB_FULL_ACCESS\nACE_MB_ASSOC_EXT_ACCT\nACE_MB_DELETE_MB_STORAGE\nACE_MB_READ_PERMISSIONS\nACE_MB_CHANGE_PERMISSION\nACE_MB_TAKE_OWNERSHIP\nALL\n");
  2118. Console.WriteLine("\nTo set a deny, use the -deny switch.");
  2119. return;
  2120. }
  2121. catch(System.Exception caught)
  2122. {
  2123. Console.WriteLine(caught.Message);
  2124. return;
  2125. }
  2126. ///
  2127. ///Remove permissions from mailbox rights
  2128. ///
  2129. case "-removefrommailboxrights":
  2130. try
  2131. {
  2132. bitflipped = true;
  2133. RemoveMailboxRights = true;
  2134. Trustee = args[i+1].ToUpper();
  2135. Permission = args[i+2].ToUpper();
  2136. if(Permission!="ACE_MB_FULL_ACCESS" && Permission!="ACE_MB_ASSOC_EXT_ACCT" && Permission!="ACE_MB_DELETE_MB_STORAGE" && Permission!="ACE_MB_READ_PERMISSIONS" && Permission!="ACE_MB_CHANGE_PERMISSION" && Permission!="ACE_MB_TAKE_OWNERSHIP" && Permission!="ALL")
  2137. {
  2138. Console.WriteLine("You must enter one of the following as a permissions mask:");
  2139. Console.WriteLine("\nACE_MB_FULL_ACCESS\nACE_MB_ASSOC_EXT_ACCT\nACE_MB_DELETE_MB_STORAGE\nACE_MB_READ_PERMISSIONS\nACE_MB_CHANGE_PERMISSION\nACE_MB_TAKE_OWNERSHIP\nALL\n");
  2140. Console.WriteLine("\nTo set a deny, use the -deny switch.");
  2141. return;
  2142. }
  2143. i+=2;
  2144. break;
  2145. }
  2146. catch(System.IndexOutOfRangeException)
  2147. {
  2148. Console.WriteLine("You must enter an account to remove permissions from, followed by the permission you wish to remove.");
  2149. Console.WriteLine("The account must be in DOMAIN\\User format, and permission must be one of the following:");
  2150. Console.WriteLine("\nACE_MB_FULL_ACCESS\nACE_MB_ASSOC_EXT_ACCT\nACE_MB_DELETE_MB_STORAGE\nACE_MB_READ_PERMISSIONS\nACE_MB_CHANGE_PERMISSION\nACE_MB_TAKE_OWNERSHIP\nALL\n");
  2151. Console.WriteLine("\nTo set a deny, use the -deny switch.");
  2152. return;
  2153. }
  2154. catch(System.Exception caught)
  2155. {
  2156. Console.WriteLine(caught.Message);
  2157. return;
  2158. }
  2159. case "-deny":
  2160. try
  2161. {
  2162. Deny = true;
  2163. break;
  2164. }
  2165. catch(System.Exception caught)
  2166. {
  2167. Console.WriteLine(caught.Message);
  2168. return;
  2169. }
  2170. //////////////////////////////////////////////
  2171. /// User Account Settings ///
  2172. //////////////////////////////////////////////
  2173. ///
  2174. ///Disable Account Switch
  2175. ///
  2176. case "-disableaccount":
  2177. try
  2178. {
  2179. disableaccount = true;
  2180. bitflipped = true;
  2181. }
  2182. catch(System.Exception caught)
  2183. {
  2184. Console.WriteLine(caught.Message);
  2185. return;
  2186. }
  2187. break;
  2188. ///
  2189. ///Enable Account Switch
  2190. ///
  2191. case "-enableaccount":
  2192. try
  2193. {
  2194. enableaccount = true;
  2195. bitflipped = true;
  2196. }
  2197. catch(System.Exception caught)
  2198. {
  2199. Console.WriteLine(caught.Message);
  2200. return;
  2201. }
  2202. break;
  2203. ///
  2204. ///Set Password Not Required
  2205. ///
  2206. case "-passwordnotrequired":
  2207. try
  2208. {
  2209. SetPasswordNotRequired = true;
  2210. bitflipped = true;
  2211. if(args[i+1]=="yes")
  2212. {
  2213. PasswordNotRequired = true;
  2214. }
  2215. else if(args[i+1]=="no")
  2216. {
  2217. //do nothing, already set to false
  2218. }
  2219. else
  2220. {
  2221. Console.WriteLine("Please specify either yes or no after the -passwordnotrequired switch.");
  2222. }
  2223. i++;
  2224. break;
  2225. }
  2226. catch (System.IndexOutOfRangeException)
  2227. {
  2228. Console.WriteLine("Please specify either yes or no after the -passwordnotrequired switch.");
  2229. return;
  2230. }
  2231. catch (System.Exception caught)
  2232. {
  2233. Console.WriteLine(caught.Message);
  2234. return;
  2235. }
  2236. //
  2237. //Password Never Expires Switch
  2238. //
  2239. case "-passwordneverexpires":
  2240. try
  2241. {
  2242. SetPasswordNeverExpires = true;
  2243. bitflipped = true;
  2244. if(args[i+1]=="yes")
  2245. {
  2246. PasswordNeverExpires = true;
  2247. }
  2248. else if(args[i+1]=="no")
  2249. {
  2250. //do nothing, already set to false
  2251. }
  2252. else
  2253. {
  2254. Console.WriteLine("Please specify either yes or no after the -passwordneverexpires switch.");
  2255. }
  2256. i++;
  2257. break;
  2258. }
  2259. catch(System.IndexOutOfRangeException)
  2260. {
  2261. Console.WriteLine("Please specify either yes or no after the -passwordneverexpires switch.");
  2262. return;
  2263. }
  2264. catch(System.Exception caught)
  2265. {
  2266. Console.WriteLine(caught.Message);
  2267. return;
  2268. }
  2269. //User Must Change Password At Next Logon
  2270. case "-mustchangepassword":
  2271. try
  2272. {
  2273. SetMustChangePassword = true;
  2274. bitflipped = true;
  2275. if(args[i+1]=="yes")
  2276. {
  2277. MustChangePasswd = true;
  2278. }
  2279. else if(args[i+1]=="no")
  2280. {
  2281. //do nothing, already set to false
  2282. }
  2283. else
  2284. {
  2285. Console.WriteLine("Please specify either yes or no after the -expirepassword switch.");
  2286. return;
  2287. }
  2288. i++;
  2289. break;
  2290. }
  2291. catch(System.IndexOutOfRangeException)
  2292. {
  2293. Console.WriteLine("Please specify yes or no after the -expirepassword switch.");
  2294. return;
  2295. }
  2296. catch(System.Exception caught)
  2297. {
  2298. Console.WriteLine(caught.Message);
  2299. return;
  2300. }
  2301. //User cannot change password
  2302. case "-cannotchangepassword":
  2303. try
  2304. {
  2305. SetCannotChangePassword = true;
  2306. bitflipped = true;
  2307. if(args[i+1]=="yes")
  2308. {
  2309. CannotChangePasswd = true;
  2310. }
  2311. else if(args[i+1]=="no")
  2312. {
  2313. //do nothing, already set to false
  2314. }
  2315. else
  2316. {
  2317. Console.WriteLine("Please specify either yes or no after the -cannotchangepassword switch.");
  2318. return;
  2319. }
  2320. i++;
  2321. break;
  2322. }
  2323. catch(System.IndexOutOfRangeException)
  2324. {
  2325. Console.WriteLine("Please specify yes or no after the -cannotchangepassword switch.");
  2326. return;
  2327. }
  2328. catch(System.Exception caught)
  2329. {
  2330. Console.WriteLine(caught.Message);
  2331. return;
  2332. }
  2333. //store password using reversible encryption
  2334. case "-usereversibleencryption":
  2335. try
  2336. {
  2337. SetUseReversibleEncryption = true;
  2338. bitflipped = true;
  2339. if(args[i+1]=="yes")
  2340. {
  2341. UseReversibleEncryption = true;
  2342. }
  2343. else if(args[i+1]=="no")
  2344. {
  2345. //do nothing, already set to false
  2346. }
  2347. else
  2348. {
  2349. Console.WriteLine("Please specify either yes or no after the -usereversibleencryption switch.");
  2350. return;
  2351. }
  2352. i++;
  2353. break;
  2354. }
  2355. catch(System.IndexOutOfRangeException)
  2356. {
  2357. Console.WriteLine("Please specify yes or no after the -usereversibleencryption switch.");
  2358. return;
  2359. }
  2360. catch(System.Exception caught)
  2361. {
  2362. Console.WriteLine(caught.Message);
  2363. return;
  2364. }
  2365. //smart card required for interactive logon
  2366. case "-smartcardrequired":
  2367. try
  2368. {
  2369. SetRequireSmartCard = true;
  2370. bitflipped = true;
  2371. if(args[i+1]=="yes")
  2372. {
  2373. RequireSmartCard = true;
  2374. }
  2375. else if(args[i+1]=="no")
  2376. {
  2377. //do nothing, already set to false
  2378. }
  2379. else
  2380. {
  2381. Console.WriteLine("Please specify either yes or no after the -smartcardrequired switch.");
  2382. return;
  2383. }
  2384. i++;
  2385. break;
  2386. }
  2387. catch(System.IndexOutOfRangeException)
  2388. {
  2389. Console.WriteLine("Please specify yes or no after the -smartcardrequired switch.");
  2390. return;
  2391. }
  2392. catch(System.Exception caught)
  2393. {
  2394. Console.WriteLine(caught.Message);
  2395. return;
  2396. }
  2397. //account cannot be delegated
  2398. case "-cannotbedelegated":
  2399. try
  2400. {
  2401. SetCannotBeDelegated = true;
  2402. bitflipped = true;
  2403. if(args[i+1]=="yes")
  2404. {
  2405. CannotBeDelegated = true;
  2406. }
  2407. else if(args[i+1]=="no")
  2408. {
  2409. //do nothing, already set to false
  2410. }
  2411. else
  2412. {
  2413. Console.WriteLine("Please specify either yes or no after the -cannotbedelegated switch.");
  2414. return;
  2415. }
  2416. i++;
  2417. break;
  2418. }
  2419. catch(System.IndexOutOfRangeException)
  2420. {
  2421. Console.WriteLine("Please specify yes or no after the -cannotbedelegated switch.");
  2422. return;
  2423. }
  2424. catch(System.Exception caught)
  2425. {
  2426. Console.WriteLine(caught.Message);
  2427. return;
  2428. }
  2429. //account cannot be delegated
  2430. case "-usedesencryption":
  2431. try
  2432. {
  2433. SetUseDESEncryption = true;
  2434. bitflipped = true;
  2435. if(args[i+1]=="yes")
  2436. {
  2437. UseDESEncryption = true;
  2438. }
  2439. else if(args[i+1]=="no")
  2440. {
  2441. //do nothing, already set to false
  2442. }
  2443. else
  2444. {
  2445. Console.WriteLine("Please specify either yes or no after the -usedesencryption switch.");
  2446. return;
  2447. }
  2448. i++;
  2449. break;
  2450. }
  2451. catch(System.IndexOutOfRangeException)
  2452. {
  2453. Console.WriteLine("Please specify yes or no after the -usedesencryption switch.");
  2454. return;
  2455. }
  2456. catch(System.Exception caught)
  2457. {
  2458. Console.WriteLine(caught.Message);
  2459. return;
  2460. }
  2461. //account cannot be delegated
  2462. case "-donotrequirekerberospreauth":
  2463. try
  2464. {
  2465. SetDoNotRequireKerberosPreAuth = true;
  2466. bitflipped = true;
  2467. if(args[i+1]=="yes")
  2468. {
  2469. DoNotRequireKerberosPreAuth = true;
  2470. }
  2471. else if(args[i+1]=="no")
  2472. {
  2473. //do nothing, already set to false
  2474. }
  2475. else
  2476. {
  2477. Console.WriteLine("Please specify either yes or no after the -donotrequirekerberospreauth switch.");
  2478. return;
  2479. }
  2480. i++;
  2481. break;
  2482. }
  2483. catch(System.IndexOutOfRangeException)
  2484. {
  2485. Console.WriteLine("Please specify yes or no after the -donotrequirekerberospreauth switch.");
  2486. return;
  2487. }
  2488. catch(System.Exception caught)
  2489. {
  2490. Console.WriteLine(caught.Message);
  2491. return;
  2492. }
  2493. //Account expires
  2494. case "-accountexpires":
  2495. try
  2496. {
  2497. SetAccountExpires = true;
  2498. bitflipped = true;
  2499. ExpireTime = args[i+1];
  2500. }
  2501. catch(System.IndexOutOfRangeException)
  2502. {
  2503. Console.WriteLine("Please specify a valid date/time after the -accountexpires switch.");
  2504. return;
  2505. }
  2506. catch(System.Exception caught)
  2507. {
  2508. Console.WriteLine(caught.Message);
  2509. return;
  2510. }
  2511. i++;
  2512. break;
  2513. //add users to a group
  2514. case "-addtogroup":
  2515. try
  2516. {
  2517. AddMembersToGroup = true;
  2518. DNOfGroup = args[i+1];
  2519. bitflipped = true;
  2520. i++;
  2521. break;
  2522. }
  2523. catch(System.IndexOutOfRangeException)
  2524. {
  2525. Console.WriteLine("Please specify the DN of the group to add members to after the -addtogroup switch.");
  2526. return;
  2527. }
  2528. catch(System.Exception caught)
  2529. {
  2530. Console.WriteLine(caught.Message);
  2531. return;
  2532. }
  2533. //remove users from a group
  2534. case "-removefromgroup":
  2535. try
  2536. {
  2537. RemoveMembersFromGroup = true;
  2538. DNOfGroup = args[i+1];
  2539. bitflipped = true;
  2540. i++;
  2541. break;
  2542. }
  2543. catch(System.IndexOutOfRangeException)
  2544. {
  2545. Console.WriteLine("Please specify the DN of the group to remove members from after the -removefromgroup switch.");
  2546. }
  2547. catch(System.Exception caught)
  2548. {
  2549. Console.WriteLine(caught.Message);
  2550. return;
  2551. }
  2552. break;
  2553. //change RDN
  2554. case "-modrdn":
  2555. try
  2556. {
  2557. ModifyRDN = true;
  2558. NewRDN = args[i+1];
  2559. bitflipped = true;
  2560. i++;
  2561. break;
  2562. }
  2563. catch(System.IndexOutOfRangeException)
  2564. {
  2565. Console.WriteLine("Please specify the new RDN value after the -modrdn switch.");
  2566. return;
  2567. }
  2568. catch(System.Exception caught)
  2569. {
  2570. Console.WriteLine(caught.Message);
  2571. return;
  2572. }
  2573. ////////////////////////////////////////////
  2574. /// Permissions Settings ///
  2575. ////////////////////////////////////////////
  2576. //
  2577. // Allow inheritable permissions to propagate switch
  2578. //
  2579. case "-allowinheritable":
  2580. try
  2581. {
  2582. if(args[i+1]=="yes")
  2583. {
  2584. AllowInheritable = true;
  2585. }
  2586. else if(args[i+1]=="no")
  2587. {
  2588. //do nothing, already false
  2589. }
  2590. else
  2591. {
  2592. Console.WriteLine("Please specify yes or no after the -allowinheritable switch.");
  2593. return;
  2594. }
  2595. Setallowinheritable = true;
  2596. bitflipped = true;
  2597. i++;
  2598. }
  2599. catch(System.IndexOutOfRangeException)
  2600. {
  2601. Console.WriteLine("Please specify yes or no after the -allowinheritable switch.");
  2602. return;
  2603. }
  2604. catch(System.Exception caught)
  2605. {
  2606. Console.WriteLine(caught.Message);
  2607. return;
  2608. }
  2609. break;
  2610. default:
  2611. //An inavlid switch was entered, notify the user
  2612. Console.WriteLine("\n" + args[i] + " is not a valid switch. Please type admodify -? for usage.");
  2613. return;
  2614. ///////////////////////////////////////////
  2615. /// Customized Attributes ///
  2616. ///////////////////////////////////////////
  2617. ///This section is why we removed the switches that modify most Integer/String values.
  2618. ///Basically, instead of building in code for all of these attributes, we can just have
  2619. ///the user name the attribute and the value instead.
  2620. case "-custom":
  2621. try
  2622. {
  2623. customAttributeName = args[i+1];
  2624. customAttributeValue = args[i+2];
  2625. i=i+2;
  2626. bitflipped = true;
  2627. break;
  2628. }
  2629. catch(System.IndexOutOfRangeException)
  2630. {
  2631. Console.WriteLine("\nPlease specify an attribute name and value.");
  2632. return;
  2633. }
  2634. catch(System.Exception caught)
  2635. {
  2636. Console.WriteLine(caught.Message);
  2637. return;
  2638. }
  2639. //for appending to multivalued attributes
  2640. case "-multi":
  2641. try
  2642. {
  2643. multi = true;
  2644. if(remove)
  2645. {
  2646. Console.WriteLine("You cannot specify -multi and -remove at the same time.");
  2647. return;
  2648. }
  2649. break;
  2650. }
  2651. catch(System.Exception caught)
  2652. {
  2653. Console.WriteLine(caught.Message);
  2654. return;
  2655. }
  2656. //for removing a single line from multivalued attributes
  2657. case "-remove":
  2658. try
  2659. {
  2660. remove = true;
  2661. if(multi)
  2662. {
  2663. Console.WriteLine("You cannot specify -multi and -remove at the same time.");
  2664. return;
  2665. }
  2666. break;
  2667. }
  2668. catch(System.Exception caught)
  2669. {
  2670. Console.WriteLine(caught.Message);
  2671. return;
  2672. }
  2673. ///////////////////////////////
  2674. /// Undo Mode ///
  2675. ///////////////////////////////
  2676. case "-undo":
  2677. try
  2678. {
  2679. UndoMode = true;
  2680. logFileName = args[i+1];
  2681. i++;
  2682. break;
  2683. }
  2684. catch(System.IndexOutOfRangeException)
  2685. {
  2686. Console.WriteLine("Please Specify the name of the logfile");
  2687. return;
  2688. }
  2689. catch(System.Exception caught)
  2690. {
  2691. Console.WriteLine(caught.Message);
  2692. return;
  2693. }
  2694. }
  2695. }
  2696. //check for MBX rights import mode
  2697. if(ImportMailboxRights)
  2698. {
  2699. if(!File.Exists("mbxrights.xml"))
  2700. {
  2701. Console.WriteLine("\nThe file mbxrights.xml does not exist in the current directory.\nMailbox rights import cannot continue.");
  2702. return;
  2703. }
  2704. bool CMDMode = true;
  2705. ImportMailboxRights import = new ImportMailboxRights();
  2706. import.ParseXML(logWriter, CMDMode, MailboxRightsOverwrite);
  2707. endTime = System.DateTime.Now;
  2708. finalCount = endTime.Subtract(startTime);
  2709. Console.WriteLine("Operation Completed in {0} seconds.", finalCount.TotalSeconds);
  2710. return;
  2711. }
  2712. //check for undo mode
  2713. if(UndoMode)
  2714. {
  2715. Console.WriteLine("\nStarting ADModify in Undo mode using log file {0}", logFileName);
  2716. bool CMDMode = true;
  2717. string ServerName = servername; //pass the server name to write changes to
  2718. Undo undo = new Undo();
  2719. undo.ParseXML(logWriter, logFileName, CMDMode, ServerName);
  2720. endTime = System.DateTime.Now;
  2721. finalCount = endTime.Subtract(startTime);
  2722. Console.WriteLine("Operation Completed in {0} seconds.", finalCount.TotalSeconds);
  2723. return;
  2724. }
  2725. //If no base DN was passed we fail
  2726. if(!haveDN)
  2727. {
  2728. Console.WriteLine("\nNo valid base DN was passed. Please use the -dn switch followed by a valid base DN.\n");
  2729. return;
  2730. }
  2731. //If no valid args were passed we fail
  2732. if(!bitflipped)
  2733. {
  2734. Console.WriteLine("\nNo valid arguments were passed. To view the admodify help, type admodcmd -?.\n");
  2735. return;
  2736. }
  2737. //If no searchbase was specified we throw an error
  2738. else if(SearchBase=="blank")
  2739. {
  2740. Console.WriteLine("Please enter a valid search base.");
  2741. return;
  2742. }
  2743. //everything checked out, now lets do some modifying.
  2744. else
  2745. {
  2746. GetDN(logWriter, LDAPFilter, subtree, SearchBase);
  2747. }
  2748. endTime = System.DateTime.Now;
  2749. finalCount = endTime.Subtract(startTime);
  2750. logWriter.Flush();
  2751. logWriter.Close();
  2752. Console.WriteLine("Operation Completed in {0} seconds.", finalCount.TotalSeconds);
  2753. return;
  2754. }
  2755. }
  2756. }