Exchange Mail.que文件重新生成

队列文件

发送邮件时邮件都是先到一个Exchange的临时的队列数据库中,然后再提交到用户邮箱中。随着时间的推移队列数据库大小会不断的增加(查看传输队列数据库位置可以查看EdgeTransport.exe.config文件中的QueueDatabasePath和QueueDatabaseLoggingPath指向的路径即为队列数据库和日志所在位置),此时就需要管理员对传输队列数据库进行维护,减小传输队列数据库的大小或者将传输队列数据库移动到其他磁盘。通常引起传输队列数据库大小不断增加的原因可能是发送大量的邮件或存在发送大附件的邮件。

所有不同的队列都存储在一个 ESE 数据库中。 默认情况下,此队列数据库位于 的传输服务器上 %ExchangeInstallPath%TransportRoles\data\Queue

与任何 ESE 数据库类似,队列数据库使用日志文件来接受、跟踪和维护数据。 若要增强性能,请首先将所有邮件事务写入日志文件和内存中,然后写入数据库文件中。 检查点文件会跟踪已提交给数据库的事务日志条目。 在 Microsoft Exchange 传输服务的正常关闭过程中,会将在事务日志中发现的未提交数据库更改提交给数据库。

检查队列

Get-Queue | Select-Object Identity, MessageCount

如果队列中MessageCount 不为0 请不要关闭”邮箱传输服务”,等待MessageCount为0时进行关闭,或者执行挂起”传输服务”,再关闭传输服务。

Suspend-Service MSExchangeTransport

挂起服务后再次查看队列 get-queue ,确保MessageCount为0

关闭传输服务进行Mail.que文件迁移

Stop-Service MSExchangeTransport

移动文件到其它磁盘空间

move-item -Path %ExchangeInstallPath%TransportRoles\data\Queue -Destination d:\Mailqueue\

启动服务

Start-Service MSExchangeTransport

Exchange 从全局地址列表中删除/隐藏 邮箱用户

How to Remove Mail Users from the Global Address List | Practical365

默认情况下,Exchange 附带五个内置地址列表和一个 GAL

查看用户所在的地址列表:

Get-Mailbox -Identity user01 | fl AddressListMembership

找出不在地址列表中显示的邮箱

Get-Mailbox -ResultSize Unlimited | where {$_.HiddenFromAddressListsEnabled -eq “$true”}

导出AD禁用的帐号
Get-ADUser -Filter {Enabled -eq “false”} -Properties * | select DisplayName,UserPrincipalName,LastLogonDate | sort LastLogonDate -Descending | Export-Csv c:\disable01.csv -Encoding utf8

将禁用的账号在地址列表中隐藏

Get-Mailbox -ResultSize unlimited | where { $_.AccountDisabled -eq ‘True’} | Set-Mailbox -HiddenFromAddressListsEnabled:$true

Exchange 通讯组和地址列表

地址列表和通讯组的区别是:用户可以向通讯组发邮件,但不能向地址列表发送邮件。地址列表完成的功能同通讯薄。用户只能从地址列表中选择目标发送邮件。

地址列表可以包含活动目录内的所用用户,通讯组,联系人和其它资源。

通讯组:New-DistributionGroup -Name “IT Administrators” -Alias itadmin -MemberJoinRestriction open

使用 Get-DistributionGroup 和 Set-DistributionGroup cmdlet 查看和更改通讯组的属性。 

Get-Mailbox -ResultSize unlimited -Filter “RecipientTypeDetails -eq ‘UserMailbox'” | Format-List Name,RecipientLimits

动态通讯组:与包含一组已定义成员的常规通讯组不同,每次向动态通讯组发送邮件时,都将根据所定义的筛选器和条件来计算该组的成员列表。 电子邮件发送到动态通讯组时,将被传递到组织中所有与为该动态通讯组定义的条件匹配的收件人。

New-DynamicDistributionGroup -IncludedRecipients MailboxUsers -Name “Mailbox Users DDG” -RecipientContainer Users

建议将每个组织单位(OU) 设置为动态通讯组,outLook 客户端默认缓存通讯组有时间为8小时,可以使用set-mailbox 更改用户为在线模式

Set-CASMailbox -Identity xiazhenghua -MAPIBlockOutlookNonCachedMode:$ture

GALs) 全局地址列表 :Exchange 自动创建的内置 GAL 包括 Active Directory 林中的每个已启用邮件的对象

设置全局地址列表过滤类型:

Set-GlobalAddressList “Default Global Address List” -RecipientFilter {(Alias -ne $null -and RecipientType -ne ‘MailUser’ -and (ObjectClass -eq ‘user’ -or ObjectClass -eq ‘Contact’ -or ObjectClass -eq ‘msExchSystemMailbox’ -or ObjectClass -eq ‘msExchDynamicDistributionList’ -or ObjectClass -eq ‘group’ -or ObjectClass -eq ‘publicFolder’))}

地址列表:地址列表是收件人的子集,它们分组在一个列表中,便于用户查找。 Exchange 附带多个内置地址列表,你可以根据组织的需求创建更多地址列表。

脱机通讯薄:OAB 包含地址列表和 GAL。 Outlook 客户端在缓存 Exchange 模式下使用 OAB,为收件人查找提供对地址列表和 GAL 的本地访问

Exchange 日志规则 、传输规则

通过日志规则监控、收集全局、个人邮件

New-journalRule -Name ‘Name01’ -JournalEmailAddress ‘user01@abc.com’ -Scope ‘Global’ -Enabled $true -Recipient ‘Admin@abc.com’

通过传输规则监控用户邮箱

New-TransportRule -Name ‘Name01’ -Comments ‘传输规则监控’ -Priority ‘0’ -Enabled $true -From ‘user01@abc.com’ -BlindCopyTo ‘Admin@thtfpc.com’

Exchange 新建邮箱

直接新建邮箱和用户

$Mailbox02 = @{
Name = ‘武思瑜’
Password = (Convertto-Securestring “N#J8xoO&” -Asplaintext -Force)
UserprincipalName = ‘wusiyu@thtfpc.com’
Alias = ‘wusiyu’
DisplayName = ‘武思瑜’
Lastname = ‘武’
FirstName = ‘思瑜’
Database = ‘DB1603’
OrganizationalUnit = ‘OU=国际信息技术(苏州)有限公司,OU=05国际(计算机)公司,OU=北京产业楼,DC=abc,DC=com’
ResetPasswordOnNextLogon = $false
SamAccountName = ‘wusiyu’
}
New-Mailbox $Mailbox02

用户创建后再启用邮箱

查询 新建用户上级所在OU

Get-ADUser -Identity yuanjixin

新建用户后再启用邮箱

$splat = @{
Name = ‘武思瑜’
AccountPassword = (Convertto-Securestring “N#J8xoO&” -Asplaintext -Force)
Enabled = $true
PasswordNeverExpires = $true
SamAccountName = ‘wusiyu’
UserprincipalName = ‘wusiyu@thtfpc.com’
DisplayName = ‘武思瑜’
Office = ‘办公产品中心’
EmailAddress = ‘wusiyu@thtfpc.com’
Title = ‘产品工程师’
Department = ‘移动产品部’
Manager = ‘yuanjixin’
Path = ‘OU=国际信息技术(苏州)有限公司,OU=05国际(计算机)公司,OU=北京产业楼,DC=abc,DC=com’
}
New-ADUser @splat

启用邮箱

$Mailbox01= @{
Identity = ‘wusiyu’
Alias = ‘wusiyu’
DataBase = ‘DB1603’
}
Enable-Mailbox @Mailbox01

查询用户所在的通讯组

Get-ADPrincipalGroupMembership wusiyu | select Name,GroupCategory
Get-ADPrincipalGroupMembership yuanjixin | select Name ,GroupCategory

添加通讯组成员

Add-DistributionGroupMember -Identity ‘同方国际北京全体员工’ -Member wusiyu

批量创建exchange邮箱

定义一个统一密码:password
$MailPasswd =ConvertTo-SecureString password -AsPlainText -Force
2.新建CSV文件NewMail.csv,格式如下
LastName,UserPrincipalName,Database,Alias,DisplayName,OrganizationalUnit,FirstName,Name,

LastName :姓
UserPrincipalName :邮箱地址
Database :指定数据库
Alias :别名
DisplayName :显示名称
OrganizationalUnit :指定一个OU
FirstName :名
Name :姓名

以管理员身份运行:Exchange Management Shell,运行下面命令

Import-Csv D:\test\NewMail.csv | ForEach-Object -Process {New-Mailbox -ResetPasswordOnNextLogon:$False -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -Database $_.Database -Alias $_.Alias -Password $MailPasswd -DisplayName $_.DisplayName -OrganizationalUnit $_.OrganizationalUnit -FirstName $_.FirstName -Name $_.Name}

批量创建邮箱用户

Import-Module activedirectory

Store the data from ADUsers.csv in the $ADUsers variable


SamAccountName	Password	Name	Path	Department	DisGroup	userPrincipalName	Title	Displayname	Description	EmailAddress	mobilePhone	Employeenumber

$Users = Import-Csv -Path C:\BulkAddUser\BulkUsers.csv

foreach ($User in $Users) {
Get-Mailbox -Identity $User.SamAccountName
}

foreach ($User in $Users) {
# Read user data from each field in each row
# the username is used more often, so to prevent typing, save that in a variable
$Username = $User.SamAccountName

# Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username}) {
     #If user does exist, give a warning
     Write-Warning "A user account with username $Username already exist in Active Directory."
}
else {
    # User does not exist then proceed to create the new user account

    # create a hashtable for splatting the parameters
    $userProps = @{
        SamAccountName             = $User.SamAccountName                   
        Path                       = $User.Path      
        Name                       = $User.Name
        DisplayName                = $User.DisplayName
        UserPrincipalName          = $user.UserPrincipalName 
        Department                 = $User.Department
        Description                = $User.Description
        Title                      = $User.Title
        EmailAddress               = $User.Email
        AccountPassword            = (ConvertTo-SecureString $User.Password -AsPlainText -Force) 
        Enabled                    = $true
        ChangePasswordAtLogon      = $true
        PasswordNeverExpires       = $false
        MobilePhone                = $User.MPhone
        EmployeeNumber             = $User.Employeenumber
    }   #end userprops   

   New-ADUser @userProps
   Enable-Mailbox -Identity  $User.SamAccountName  -Alias $User.SamAccountName  -Database DB1602
   Add-DistributionGroupMember -Identity  qyjbdrt -Member $User.SamAccountName

  Write-Host "The user ADaccount $User is created." -ForegroundColor Green




} #end else

}

Index