如何安装Active Directory PowerShell模块

在本指南中,我们将向您展示如何在几乎任何版本的Windows上安装Active Directory PowerShell模块。在PowerShell中安装Active Directory (AD)模块为IT专业人员提供了方便和安全的远程访问权限,以便管理他们的AD环境,而无需交互式地登录到他们的域控制器。

微软不建议非常普遍和普遍的做法,即交互式登录到Active Directory 域控制器 (DCs) 来工作在Active Directory中。这是一种根本的安全风险,也是低效的,只举两个弊端。微软建议的最佳做法是远程和安全地使用远程服务器管理工具 (RSAT) 装备,其中包括Active Directory模块 for Windows PowerShell

广告

安装Active Directory PowerShell模块

I will assist you in the installation of this rather powerful module on the varying Windows Server and Windows client operating systems. Hopefully, this guide will help you be more efficient, especially when it comes to PowerShell scripting and productivity gains.

Windows 7 (Windows Server 2008 R2)

等待……微软已经停止支持Windows 7大约两年半了(在撰写本文时)。是的,你说得对。没有人应该继续使用Windows 7。但正如我们都知道的那样,绝大多数企业和中小型企业肯定仍然有一些Windows 7机器藏在幕后。

下载并安装Windows 7的远程服务器管理工具(RSAT)

首先,您需要下载并安装Windows 7的远程服务器管理工具(RSAT)。现在,如果您浏览这个官方微软文档链接,您会看到有关Windows 7的RSAT的讨论。但无论您怎么尝试,您都不会找到下载链接(就是没有)。

长话短说,Microsoft已经移除了Windows 7的RSAT软件包的官方下载。但是,由于web.archive.org,过去某种程度上得以保留:您可以从this link下载该软件包。

广告

下载后,双击打开,点击安装更新,然后点击接受许可条款。

Installing the RSAT on Windows 7

安装完成后,可以继续下一步。点击

Microsoft being all helpful and showing you how to proceed – how nice! ?

开始 -> 控制面板 -> 程序,然后选择“打开或关闭 Windows 功能”。

Next, we need to enable the features in Windows

展开远程服务器管理工具 -> 角色管理工具 -> AD DS 和 AD LDS 工具,选中“Windows PowerShell 的活动目录模块”,点击确定

广告

Finally selecting the exact feature we need!

然后将开始安装PowerShell模块,可能需要几分钟时间。

Installation commencing

之后,它会愉快地消失。点击开始 -> 管理工具。在顶部,您可以点击Windows PowerShell的活动目录模块

The new feature in the Administrative Tools folder

。就是这样。我刚输入 Get-ADUser -filter *来测试和验证模块是否有效:

Get-ADUser -filter *

如下所示,该模块已成功连接到我的Active Directory并输出了我实验室中的所有用户帐户。太棒了!

Running ‘Get-ADUser’ from the new module!

Windows Server 2008 R2

因此,关于在Windows Server 2008 R2上安装这个,过程相当相似。这并不奇怪,因为这个版本的Windows Server和Windows 7共享相同的代码库。

以下是区别和您需要执行的步骤。不用担心,这很简单:

1. 继续使用相同的下载源获取RSAT工具并安装它们。

2. 打开服务器管理器,然后点击“添加功能

3. 滚动查找远程服务器管理工具 -> 角色管理工具 -> AD DS和AD LDS工具 -> 适用于Windows PowerShell的Active Directory模块

您也可以使用以下PowerShell命令安装该模块:

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell

完成!

Windows 10

Windows 10上,微软在减少安装RSAT工具所需的时间以及各种难题方面取得了重大进展 – 他们将这些工具包含在操作系统的位中,并通过可选功能进行安装。

点击开始 -> 设置 -> 应用 -> 可选功能

How to start the installation of the RSAT Tools on Windows 10

点击顶部的“添加功能”按钮,然后向下滚动并勾选“RSAT: Active Directory 域服务和轻量目录服务工具”。

点击安装按钮,然后Windows 10将启用该功能。

接下来,打开Windows 10的开始菜单,开始键入“module”,你将找到“用于 Windows PowerShell 的 Active Directory 模块”。单击它,你就可以使用了!

Finding the new module in the Start Menu

I’ll run the same Get-ADUser command, the output looks familiar, doesn’t it? ?

Get-ADUser -filter *
Running Get-ADUser with the new module in Windows 10

Windows 11

在Windows 11上的过程与Windows 10非常相似,只不过设置的布局已经进行了一些调整。让我们在我的实验室中的一个Windows 11客户端虚拟机上开始这个过程。

点击开始 -> 设置 -> 应用 -> 可选功能

In Settings -> Apps, you’ll find Optional Features. Click this to install the AD Module

点击右上角的“查看功能”按钮,然后向下滚动找到“RSAT: Active Directory 域服务和轻量目录服务工具”。

Click ‘View features’ to find and select the prize

点击下一步,Windows 11将为您安装该功能。然后,像上面那样,再次点击开始按钮,开始输入“module”,然后就可以了!

Using the Start Menu search to find our new module

点击“Windows PowerShell的活动目录模块”。我们可以使用相同的Get-ADUser命令在本地和我们的Active Directory域中确认权限。

Get-ADUser -filter *
We are 3 for 3 here. Very cool!

Windows Server 2012 R2(Windows Server 2016、2019、2022和Windows 8.1)

由于这些Windows版本之间的安装过程非常相似,我将在这里介绍一套步骤。这将涵盖Windows Server 2012 R2Windows Server 2016Windows Server 2019Windows Server 2022(这也非常接近适用于Windows 8.1)

提醒:Windows 8.1将于2023年1月结束支持,Windows Server 2012/Windows Server 2012 R2将于2023年10月结束支持。请做好准备!

再次说明,这些Windows版本共享相同的代码库,因此操作步骤非常相似。让我们从我在Windows Server 2022 Active Directory Hyper-V实验室中新的、全面打过补丁的Windows Server 2012 R2成员服务器开始。

Windows Server 2012 R2 – Ready to go!

我们继续打开服务器管理器,然后点击添加角色和功能

Adding Roles and Features to install RSAT Tools

点击下一步几次直到进入“选择功能”屏幕。与之前操作一样,展开至“远程服务器管理工具 -> 角色管理工具 -> AD DS 和 AD LDS 工具 -> 然后选择 Windows PowerShell 的 Active Directory 模块。”

Selecting the AD module for Windows PowerShell

在下一个屏幕上,点击安装,然后就完成了!

Installation succeeded! Let’s fire her up!

点击开始 -> 管理工具。看哪,它在那里。打开“Windows PowerShell 的 Active Directory 模块”。让我们再次使用相同的Get-ADUser命令。

Get-ADUser -filter *
I know…I probably could have come up with some varying commands, but, you get the idea… ?

PowerShell Core 6.0/7.x

有一些其他的生产力功能可帮助提高IT专业人员的效率。这包括在 PowerShell Core 6.x/7.x 上安装 Active Directory 模块的方法。我将在我的 Windows 10 版本 21H2 VMs 上演示这个过程。

第一步是安装如上所述的 RSAT 工具。您可以按照上面“Windows 10”部分中提到的不同步骤进行操作。

安装好工具后,您可以安装最新版本的 PowerShell Core,就像我撰写时的 PowerShell 7.2.5。您可以在 此页面 找到下载链接。

Installing PowerShell (Core) 7.2.5

在打开设置向导后,点击 下一步。在“可选操作”屏幕上,您可以看到“启用 PowerShell 远程”选项。请确保选中该选项。

Selecting the ‘Enable PowerShell remoting’ feature

点击几次 下一步,然后点击 安装

Installing PowerShell 7

安装完成后,您可以在开始菜单中以管理员身份启动它。

Launching PowerShell (Core) 7 as an administrator

由于安装的模块基本上“跟随”安装的不同版本的 PowerShell,我能够使用 PowerShell(Core)7.2.5 并直接运行 Get-ADUser 命令。

Get-ADUser -filter *
Running Get-ADUser in PowerShell (Core) 7.2.5!

使用PowerShell远程和交互式会话

另一个非常强大的功能是在连接到域控制器的同时能够在客户端计算机上启动一个远程交互式PowerShell会话。让我用下面的命令演示如何做到这一点:

Enter-PSsession ws16-dc1
Using Enter-PSsession to remotely run PowerShell on my domain controller!

所以,如果你的IT安全人员因为某种原因不希望在客户端计算机上安装RSAT工具,你仍然可以在Active Directory中通过PowerShell完成你的任务,而无需登录到你的DC。挺巧妙的技巧,对吧?

我们接下来的选项是使用所谓的隐式远程。这允许你在本地会话中运行AD cmdlet。然而,命令是在DC上远程运行的。运行以下命令来实现这一点。

下面的第一个命令在我的名称为ws16-dc1的DC上启动一个PowerShell会话:

$Session = New-PSSession -ComputerName ws16-dc1

接下来的命令将远程会话中的Active Directory模块导入到我们的本地会话中:

Import-Module -PSsession $session -name ActiveDirectory
Importing the AD Module from your DC

你运行的所有命令实际上都是在你的域控制器上处理和运行的。

将远程AD模块导出到本地模块

这里我们可以完成的最后一项任务是将AD cmdlet从远程会话导出到本地模块。下面的示例命令将通过在PowerShell\Modules\RemoteAD文件夹下的文档文件夹中创建一个本地模块来完成此任务。

$session = New-PSSession -ComputerName ws16-dc1
Export-PSSession -Session $session -Module ActiveDirectory -OutputModule RemoteAD
Remove-PSSession -Session $session
Import-Module RemoteAD
Exporting the remote Active Directory module from my DC to my local module

和之前执行过的步骤一样,我们再次使用隐式远程,意味着我们使用的所有cmdlet都将在我们指定的域控制器上远程运行。本地RemoteAD模块将连接到DC上的cmdlet。

额外提示:如果您想在其他客户端计算机上使用这个RemoteAD模块,可以将RemoteAD文件夹复制到其他计算机上的PowerShell Core模块文件夹。

You can copy any modules listed here to other machines to auto-import them

这两种方法之间的区别在于 – PowerShell仅在第一次使用AD cmdlet时与域控制器建立连接。这是一个持久性连接。您不必将上述命令添加到您的脚本或配置文件中,因为PowerShell会自动加载它们。但是,请注意如果您更新域控制器上的AD模块,则可能需要重复这些步骤。

结论

发现一些IT专业人员需要经历的流程非常简单令人耳目一新。感谢Microsoft在过去的十年中保持在PowerShell中安装此Active Directory模块的整个流程非常简化和一致!每一点帮助都很重要。

由于像这样的帖子,如果你需要抓住你的迪洛雷安(DeLorean)回到过去,你将拥有完成任务所需的一切。谢谢你的阅读,请在下方评论区留下任何评论或问题。

Source:
https://petri.com/install-active-directory-powershell-module/