当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

作者:精品下载站 日期:2024-12-14 18:13:37 浏览:14 分类:玩电脑

使用 PowerShell 在 Exchange Server 中创建批量邮箱


在上一篇文章中,我们安装了 Exchange Server。它是组织中的第一台 Exchange Server,这意味着没有配置邮箱。因此,我们需要为AD中现有的用户创建邮箱。在本文中,您将了解如何使用 PowerShell 在 Exchange Server 中创建批量邮箱。

空邮箱区域

安装完Exchange Server后,我们想看看邮箱区域。登录 Exchange 管理中心并导航到收件人,然后单击邮箱。邮箱区域几乎是空的,只显示一个邮箱。这是我们用于安装 Exchange Server 2016 的帐户。

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

我们可以通过单击+图标并按照向导操作在Exchange管理中心创建邮箱。对于几个用户来说,这会很棒。如果您有超过一千个用户怎么办?答案是,使用 PowerShell 在 Exchange Server 中批量创建邮箱。

为现有用户创建邮箱

以管理员身份运行 Exchange 命令行管理程序。使用 Get-User cmdlet 验证用户是否位于 AD 中。之后,使用 Enable-Mailbox cmdlet 在 AD 中为用户创建邮箱。如果您有多个数据库,它会自动查找一个健康的数据库并创建邮箱。

[PS] C:\>Get-User -Identity "Sebastian Lambert"

Name              RecipientType
----              -------------
Sebastian Lambert User


[PS] C:\>Get-user "Sebastian Lambert" | Enable-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Sebastian Lambert         Sebastian.Lambert    ex01-2016        Unlimited

我们喜欢为AD中的现有用户创建一个邮箱,但是该邮箱需要在特定的数据库中创建。在我们的组织中,我们在 Exchange 中配置了两个数据库。

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

让我们为 DB02 中的现有用户创建一个新邮箱。我们将使用-Database参数。

[PS] C:\>Get-User -Identity "Jasmine Turner"

Name           RecipientType
----           -------------
Jasmine Turner User


[PS] C:\>Get-User -Identity "Jasmine Turner" | Enable-Mailbox -Database "DB02" 

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Jasmine Turner            Jasmine.Turner       ex01-2016        Unlimited

邮箱创建成功。查看邮箱区域中的 EAC。单击刷新图标,将显示两个新邮箱。

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

如果我们需要为 AD 中的现有用户启用一千个邮箱怎么办?

为 AD OU 中的现有用户创建批量邮箱

我们喜欢基于OU为现有用户批量创建邮箱。 OU Finance 中的用户将需要一个邮箱。首先,让我们使用 PowerShell 查找组织单位的可分辨名称。

[PS] C:\>Get-ADOrganizationalUnit -Properties CanonicalName -Filter *| Sort-Object CanonicalName | Format-Table CanonicalName, DistinguishedName

CanonicalName                                    DistinguishedName
-------------                                    -----------------
exoip.local/Company                              OU=Company,DC=exoip,DC=local
exoip.local/Company/Exchange                     OU=Exchange,OU=Company,DC=exoip,DC=local
exoip.local/Company/Exchange/Distribution Groups OU=Distribution Groups,OU=Exchange,OU=Company,DC=exoip,DC=local
exoip.local/Company/Exchange/Security Groups     OU=Security Groups,OU=Exchange,OU=Company,DC=exoip,DC=local
exoip.local/Company/Exchange/SharedMailbox       OU=SharedMailbox,OU=Exchange,OU=Company,DC=exoip,DC=local
exoip.local/Company/Groups                       OU=Groups,OU=Company,DC=exoip,DC=local
exoip.local/Company/Servers                      OU=Servers,OU=Company,DC=exoip,DC=local
exoip.local/Company/Servers/Exchange             OU=Exchange,OU=Servers,OU=Company,DC=exoip,DC=local
exoip.local/Company/Users                        OU=Users,OU=Company,DC=exoip,DC=local
exoip.local/Company/Users/Finance                OU=Finance,OU=Users,OU=Company,DC=exoip,DC=local
exoip.local/Company/Users/HR                     OU=HR,OU=Users,OU=Company,DC=exoip,DC=local
exoip.local/Company/Users/IT                     OU=IT,OU=Users,OU=Company,DC=exoip,DC=local
exoip.local/Company/Users/Sales                  OU=Sales,OU=Users,OU=Company,DC=exoip,DC=local
exoip.local/Domain Controllers                   OU=Domain Controllers,DC=exoip,DC=local
exoip.local/Microsoft Exchange Security Groups   OU=Microsoft Exchange Security Groups,DC=exoip,DC=local

复制专有名称值并将其粘贴到下一个命令中。验证用户是否显示,然后为 OU Finance 中的用户启用邮箱。

[PS] C:\>Get-User -OrganizationalUnit "OU=Finance,OU=Users,OU=Company,DC=exoip,DC=local"

Name            RecipientType
----            -------------
Jack Slater     User
David Wallace   User
Lillian Ellison User
Benjamin Watson User
Charles Lewis   User
Vanessa Sharp   User
Lauren Terry    User

[PS] C:\>Get-User -OrganizationalUnit "OU=Finance,OU=Users,OU=Company,DC=exoip,DC=local" | Enable-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Jack Slater               Jack.Slater          ex01-2016        Unlimited
David Wallace             David.Wallace        ex01-2016        Unlimited
Lillian Ellison           Lillian.Ellison      ex01-2016        Unlimited
Benjamin Watson           Benjamin.Watson      ex01-2016        Unlimited
Charles Lewis             Charles.Lewis        ex01-2016        Unlimited
Vanessa Sharp             Vanessa.Sharp        ex01-2016        Unlimited
Lauren Terry              Lauren.Terry         ex01-2016        Unlimited

OU Finance用户的邮箱已经创建好了,太好了。我们将通过单击刷新图标在 EAC 中确认这一点。

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

从文本文件创建批量邮箱

如果您想为选定的用户批量创建邮箱怎么办?假设 IT OU 中只有 7 个用户需要获取邮箱,但 IT 部门有 50 个用户。

首先,让我们获取 OU 中的用户列表(在我们的示例中,我们将仅输出 10 个用户)。之后,将 AD 用户从给定 OU 导出到文本文件。

[PS] C:\>Get-ADUser -ResultSetSize $Null -filter * -SearchBase "OU=IT,OU=Users,OU=Company,DC=exoip,DC=local" | Select-Object -ExpandProperty Name
Amy Pullman
Deirdre Gray
Kevin Glover
Ryan Carr
Sam MacDonald
Katherine Peters
Irene Alsop
Faith Dowd
Stephanie Underwood
Amanda Clarkson

[PS] C:\>Get-ADUser -ResultSetSize $Null -filter * -SearchBase "OU=IT,OU=Users,OU=Company,DC=exoip,DC=local" | Select-Object -ExpandProperty Name | Out-File "C:\export_users.txt" -Encoding UTF8

在导出的路径中找到文本文件。该文本文件包含 50 个用户。

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

通过删除或添加额外的用户来编辑列表。现在它包含七个用户。将文本文件另存为 C:\ 驱动器中的 import_users。

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

现在让我们为文本文件中的用户批量创建邮箱。

[PS] C:\>Get-Content "C:\import_users.txt" | Enable-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Piers Bower               Piers.Bower          ex01-2016        Unlimited
Kylie Davidson            Kylie.Davidson       ex01-2016        Unlimited
Richard Grant             Richard.Grant        ex01-2016        Unlimited
Leonard Clark             Leonard.Clark        ex01-2016        Unlimited
Ruth Dickens              Ruth.dickens         ex01-2016        Unlimited
Grace Rees                Grace.Rees           ex01-2016        Unlimited
Max Fraser                Max.Fraser           ex01-2016        Unlimited

从文本文件创建邮箱,这太棒了。我们来看看EAC。单击刷新图标。

[玩转系统] 使用 PowerShell 在 Exchange Server 中创建批量邮箱

邮箱显示在 EAC 中。我希望这可以帮助您为 AD 中的现有用户批量创建新邮箱。使用 PowerShell 执行此操作会更快。

继续阅读:使用 PowerShell 将 AD 用户批量移动到另一个 OU »

结论

您学习了如何使用 PowerShell 在 Exchange Server 中创建批量邮箱。如果您需要为一个小组创建邮箱,您可以在 Exchange 管理中心 (EAC) 中执行此操作。另一方面,如果您有许多用户需要邮箱,请使用 PowerShell 批量创建新邮箱以节省时间。

您喜欢这篇文章吗?您可能还喜欢在 Exchange 混合中批量创建 Office 365 邮箱。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯