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

[玩转系统] 使用 PowerShell 获取 Active Directory 计数

作者:精品下载站 日期:2024-12-14 22:35:11 浏览:14 分类:玩电脑

使用 PowerShell 获取 Active Directory 计数


如何对 Active Directory 对象进行计数?为什么需要 AD 对象计数?在我们的示例中,我们希望在安装和配置 Azure AD Connect 之前获得总计数。这是因为我们需要了解最低服务器要求的 AD 对象总数。在本文中,我们将了解如何使用 PowerShell 对 AD 对象进行计数。

统计AD用户数

使用 PowerShell 对 AD 用户进行计数。使用获取 AdUser cmdlet。

PS C:\> (Get-AdUser -Filter *).Count
5143

AD组计数

使用 PowerShell 对 AD 组进行计数。使用 Get-ADGroup cmdlet。

PS C:\> (Get-ADGroup -Filter *).Count
88

计算AD计算机数量

使用 PowerShell 对 AD 计算机进行计数。使用 Get-ADComputer cmdlet。

PS C:\> (Get-ADComputer -Filter *).Count
8

获取AD总数

让我们使用 PowerShell 添加用户、组和计算机计数。使用以下脚本,将其复制并粘贴到 PowerShell ISE 中。您还可以下载 Get-ADCount.ps1 脚本并从 PowerShell 运行它。

$ADUser = (Get-AdUser -Filter *).Count
$ADGroup = (Get-ADGroup -Filter *).Count
$ADComputer = (Get-ADComputer -Filter *).Count
$ADObjects = $ADUser + $ADGroup + $ADComputer
$ADObjects

这是运行脚本后的样子。 AD 对象总数为 5239

PS C:\> $ADUser = (Get-AdUser -Filter *).Count
$ADGroup = (Get-ADGroup -Filter *).Count
$ADComputer = (Get-ADComputer -Filter *).Count
$ADObjects = $ADUser + $ADGroup + $ADComputer
$ADObjects
5239

使用 PowerShell 脚本获取 Active Directory 信息

获取 Active Directory 计数的一个极好方法是运行 Get-ADInfo.ps1 PowerShell 脚本。这将显示 AD 对象计数以及有关 Active Directory 的更多信息。

PS C:\> cd C:\scripts
PS C:\scripts> .\Get-ADinfo.ps1

Active Directory Info

Computers =     8
Workstions =    3
Servers =       5
Users =         5143
Groups =        88

Active Directory Forest Name =   exoip.local
Active Directory Forest Mode =   Windows2016Forest
Active Directory Domain Mode =   Windows2016Domain
Active Directory Schema Version is 88 which corresponds to Windows Server 2019/Windows Server 2022

FSMO Role Owners
Schema master               DC01-2019.exoip.local
Domain naming master        DC01-2019.exoip.local
PDC                         DC01-2019.exoip.local
RID pool manager            DC01-2019.exoip.local
Infrastructure master       DC01-2019.exoip.local
The command completed successfully.

下面的屏幕显示了它的样子。

[玩转系统] 使用 PowerShell 获取 Active Directory 计数

就是这样!它对您检索 AD 对象总数有帮助吗?

了解更多:获取 Exchange 中的总用户数 »

结论

您学习了如何使用 PowerShell 获取 Active Directory 计数。在开始部署使用 AD 对象的应用程序之前,对 AD 对象进行计数,并且您想知道 AD 中存在多少个 AD 对象。另一种方法是运行 Get-ADInfo.ps1 PowerShell 脚本来获取 AD 对象计数和更多信息。

您喜欢这篇文章吗?您可能还喜欢检查 Exchange 健康邮箱。不要忘记关注我们并分享这篇文章。

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

取消回复欢迎 发表评论:

关灯