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

[玩转系统] 在 PowerShell 中获取 AD 用户属性

作者:精品下载站 日期:2024-12-14 17:31:47 浏览:14 分类:玩电脑

在 PowerShell 中获取 AD 用户属性


Active Directory 是一个中央存储库,用于存储有关 Windows 网络中的用户、计算机和其他对象的信息。管理员通常需要检索 Active Directory 用户属性以执行报告或自动化任务。

PowerShell 中的 Get-AdUser cmdlet 根据 Active Directory 中的搜索检索指定的用户对象信息或多用户帐户信息。

在本文中,我们将讨论如何使用 PowerShell 中的 Get-AdUser 命令获取 aduser 属性。

如何在 PowerShell 中获取 AdUser 属性

使用 PowerShell 中的 Get-AdUser 命令获取有关 Active Directory 用户的信息。此命令使用 Properties * 参数来获取在对象上设置的所有属性。

要在 PowerShell 中获取 aduser 属性,请使用以下命令。

  1. 启动 PowerShell - 使用管理员权限打开 PowerShell 终端。
  2. 键入命令 Get-AdUser -Identity toms -Properties * 并按 Enter 键。
Get-AdUser -Identity toms -Properties *

在上面的 PowerShell 脚本中,Get-AdUser 命令使用 Identity 参数来指定我们要检索其所有属性的用户名。 Properties * 参数检索 Active Directory 中给定用户可用的所有属性。

上述 PowerShell 脚本的输出返回与广告用户帐户关联的广告属性及其值的完整列表。

[玩转系统] 在 PowerShell 中获取 AD 用户属性

它返回广告用户的所有属性,例如 AccountExpires、City、CN、Company、Department DistinguishedName 等...

要显示 DisplayName、Department、DeskLocation 和 City 等属性,请运行以下 PowerShell 脚本。

Get-AdUser -Identity toms -Properties * | Select DisplayName, Department, DeskLocation,City

在上面的 PowerShell 脚本中,Get-AdUser 命令检索名为“toms”的 Identity 参数指定的用户的用户信息。此命令使用 Properties * 参数获取所有属性,并将结果用户对象通过管道传递给 Select 命令。

Select 命令显示给定用户的 DisplayName、Department、DeskLocation 和 City 名称。

上述 PowerShell 脚本的输出显示用户属性。

PS C:\> Get-AdUser -Identity toms -Properties * | Select DisplayName, Department, DeskLocation,City

DisplayName Department DeskLocation City
----------- ---------- ------------ ----
Tom Smith   SALES      B1D001       Houston


PS C:\>

结论

希望上面关于如何在PowerShell中使用Get-AdUser命令获取aduser所有属性的文章对您有所帮助。

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

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

取消回复欢迎 发表评论:

关灯