/// <summary> /// 启用AD邮件组,显示在exchange组中,可以首发邮件 /// </summary> /// <param name="identity">组的标识</param> /// <param name="config"></param> /// <returns></returns> public static ExcuseResult EnableDistributionGroup(string identity, ExchangeAdminConfig config) { ExcuseResult er = new ExcuseResult(); var command = new Command("Enable-DistributionGroup"); command.Parameters.Add("Identity", identity); if (!string.IsNullOrEmpty(config.DomainController)) { command.Parameters.Add("DomainController", config.DomainController); } try { string result = RunExchangePowerShellScript(command, config); if (!string.IsNullOrEmpty(result) && result != "FAIL") { return(er.SetSuccessResult()); } return(er.SetFailResult()); } catch (Exception ex) { return(er.SetErrorResult(ex.Message)); } }
/// <summary> /// 禁用用户邮箱 /// </summary> /// <param name="userCode">工号</param> /// <param name="config"></param> /// <returns></returns> public static ExcuseResult DisableUserMailBox(string userCode, ExchangeAdminConfig config) { var er = new ExcuseResult(); List <string> srcpirt = new List <string> { $"Disable-Mailbox {userCode} -Confirm:$False" }; try { IEnumerable <PSObject> output; string result = RunExchangePowerShellScript(srcpirt, config, out output); if (output != null) { var psObjects = output as IList <PSObject> ?? output.ToList(); PSObject psObject = psObjects[0]; foreach (PSPropertyInfo psPropertyInfo in psObject.Properties) { er.Reuslt = psPropertyInfo.Value; return(er.SetSuccessResult()); } } return(er.SetFailResult()); } catch (Exception ex) { return(er.SetErrorResult(ex.Message)); } }
/// <summary> /// 判断是否存在邮箱 /// </summary> /// <param name="userCodeOrEmail">工号或者邮箱</param> /// <param name="config"></param> /// <returns></returns> public static ExcuseResult IsExitsUserMailBox(string userCodeOrEmail, ExchangeAdminConfig config) { ExcuseResult er = new ExcuseResult(); var command = new Command("Get-Mailbox"); command.Parameters.Add("Identity", userCodeOrEmail); if (!string.IsNullOrEmpty(config.DomainController)) { command.Parameters.Add("DomainController", config.DomainController); } try { string result = RunExchangePowerShellScript(command, config); if (!string.IsNullOrEmpty(result) && result != "FAIL") { return(er.SetSuccessResult()); } return(er.SetFailResult()); } catch (Exception ex) { return(er.SetErrorResult(ex.Message)); } }
/// <summary> /// 创建用户邮箱帐号 /// </summary> /// <param name="entity"></param> /// <param name="config"></param> /// <returns></returns> public static ExcuseResult CreateUserMailBox(AdEntity entity, ExchangeAdminConfig config) { ExcuseResult er = new ExcuseResult(); var command = new Command("Enable-Mailbox"); command.Parameters.Add("Identity", entity.SamAccountName); command.Parameters.Add("Alias", entity.Alias); command.Parameters.Add("Database", entity.Database); command.Parameters.Add("Password", String2SecureString(entity.Password)); if (!string.IsNullOrEmpty(config.DomainController)) { command.Parameters.Add("DomainController", config.DomainController); } try { string result = RunExchangePowerShellScript(command, config); if (!string.IsNullOrEmpty(result) && result != "FAIL") { return(er.SetSuccessResult()); } return(er.SetFailResult()); } catch (Exception ex) { return(er.SetErrorResult(ex.Message)); } }
/// <summary> /// 创建邮箱组 /// </summary> /// <param name="entity"></param> /// <param name="members">可以是邮箱集合,或者是用户的SamAccountName、Name等</param> /// <param name="exConfig"></param> public static ExcuseResult NewDistributionGroup(ExchangeMailGroup entity, List <string> members, ExchangeAdminConfig exConfig) { var er = new ExcuseResult(); var command = new Command("New-DistributionGroup"); command.Parameters.Add("Name", entity.Name); command.Parameters.Add("OrganizationalUnit", entity.OrganizationalUnit); if (!string.IsNullOrEmpty(entity.Alias)) { command.Parameters.Add("Alias", entity.Alias); } if (!string.IsNullOrEmpty(entity.SamAccountName)) { command.Parameters.Add("SamAccountName", entity.SamAccountName); } if (!string.IsNullOrEmpty(entity.Type)) { command.Parameters.Add("Type", entity.Type); } if (!string.IsNullOrEmpty(entity.DomainController)) { command.Parameters.Add("DomainController", entity.DomainController); } if (!string.IsNullOrEmpty(entity.DisplayName)) { command.Parameters.Add("DisplayName", entity.DisplayName); } if (!string.IsNullOrEmpty(entity.Notes)) { command.Parameters.Add("Notes", entity.Notes); } if (members != null && members.Count > 0) { var menbersStr = string.Join(",", members); command.Parameters.Add("Members", menbersStr); } try { string result = RunExchangePowerShellScript(command, exConfig); if (!string.IsNullOrEmpty(result) && result != "FAIL") { return(er.SetSuccessResult()); } return(er.SetFailResult()); } catch (Exception ex) { return(er.SetErrorResult(ex.Message)); } }
/// <summary> /// 创建AD帐号并开通Exchange帐号 /// </summary> /// <param name="entity"></param> /// <param name="config"></param> /// <returns></returns> public static ExcuseResult CreateAdAccountAndOpenExcahnge(AdEntity entity, ExchangeAdminConfig config) { ExcuseResult er = new ExcuseResult(); var command = new Command("New-Mailbox"); command.Parameters.Add("Name", entity.Name); command.Parameters.Add("Alias", entity.Alias); command.Parameters.Add("UserPrincipalName", entity.UserPrincipalName + "@" + entity.Ldap); command.Parameters.Add("SamAccountName", entity.SamAccountName); command.Parameters.Add("FirstName", entity.FirstName); command.Parameters.Add("LastName", entity.LastName); command.Parameters.Add("Password", String2SecureString(entity.Password)); command.Parameters.Add("ResetPasswordOnNextLogon", false); command.Parameters.Add("OrganizationalUnit", $"{entity.Ldap}/{entity.OrganizationalUnit}"); command.Parameters.Add("Database", entity.Database); command.Parameters.Add("DisplayName", entity.DisplayName); if (!string.IsNullOrEmpty(config.DomainController)) { command.Parameters.Add("DomainController", config.DomainController); } try { string result = RunExchangePowerShellScript(command, config); if (!string.IsNullOrEmpty(result) && result != "FAIL") { return(er.SetSuccessResult()); } return(er.SetFailResult()); } catch (Exception ex) { return(er.SetErrorResult(ex.Message)); } }