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

[玩转系统] 让 AdUsers 排除 Active Directory 中的特定 OU

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

让 AdUsers 排除 Active Directory 中的特定 OU


要获取活动目录中排除特定 OU 的广告用户,您可以使用 Get-AdUser cmdlet 和 SearchBase 参数来获取父 OU 中的所有用户,并使用 where 条件来获取排除特定 OU 的广告用户。

要排除父 OU 下的特定子 OU 并从所有其他 OU 获取广告用户,我们必须使用 Where-Object 命令来过滤 OU 的专有名称与我们所选择的特定子 OU 不同的地方。想要排除。

在本文中,我们将讨论如何使用 Get-AdUser cmdlet 让 aduser 排除 Active Directory 中的特定 OU。

获取 AdUser 排除特定 OU

使用带有 SearchBase 参数的 Get-AdUser cmdlet 指定父 OU。它返回父 OU 和子 OU 中的所有 Active Directory 用户。

通过管道传输第一个命令的输出,它将所有广告用户从 OU 返回到 Where-Object,以应用过滤器,检查 distinguishedname 是否与我们想要的 OU 不同排除。

 Get-ADUser -Filter * -SearchBase 'OU=SHELLUSERS,DC=SHELLPRO,DC=LOCAL' | Where-Object { $_.DistinguishedName -notlike '*OU=HR*' } | Select Name,DistinguishedName

在上面的 PowerShell 脚本中,它获取不包括特定 OU (HR) 的 adusers,并显示 aduser 名称和 DistinguishedName。

它返回 Finance 和 SHELLUsers OU 中的广告用户,并排除 HR OU 中的广告用户。

上述用于让 aduser 排除特定 OU 的 PowerShell 脚本的输出为:

[玩转系统] 让 AdUsers 排除 Active Directory 中的特定 OU

结论

我希望上述有关如何使用 Get-AdUser cmdlet 获取广告用户并排除特定 OU 的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

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

取消回复欢迎 发表评论:

关灯