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

[玩转系统] 使用 PowerShell 获取 AD 计算机描述

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

使用 PowerShell 获取 AD 计算机描述


我们可以使用PowerShell中的Get-AdComputer来获取Active Directory计算机的描述。 AD计算机具有描述属性。

我们可以使用 Active Directory 用户和计算机 (ADUC) 控制台管理单元界面并使用 PowerShell 中的 Get-AdComputer 命令来获取 Active Directory 计算机的描述。

在本文中,我们将讨论如何获取广告计算机描述,如何通过描述获取广告计算机以及如何在活动目录中查找描述包含搜索条件的计算机。

使用 PowerShell 获取广告计算机描述

使用PowerShell中的Get-AdComputer,我们可以获取广告计算机描述字段信息。

 Get-AdComputer -Identity ENGG-PRO -Properties * | Select-Object Name, Description

在上面获取带有描述的 adcomputer 的 PowerShell 脚本中,Get-AdComputer 使用 Identity 参数来获取计算机名称。它通过管道传输广告计算机对象信息。 Select-Object cmdlet 选择广告计算机的名称和描述并将其打印在控制台上。

我们使用 Properties * 来获取其他属性,例如计算机的描述字段。

上述用于获取广告计算机描述的 PowerShell 脚本的输出为:

[玩转系统] 使用 PowerShell 获取 AD 计算机描述

获取 AD 计算机的描述

使用 PowerShell 中的 Get-AdComputer cmdlet,它可以获取 Active Directory 中的一台或多台计算机。

Get-AdComputer -Filter * -Properties Name, Description | Select-Object Name,Description

在上面的 PowerShell 脚本中,Get-AdComputer Filter * 参数用于获取具有活动目录中可用描述的广告计算机。

显示所有广告计算机描述的上述脚本的输出是:

PS C:\> Get-AdComputer -Filter * -Properties Name, Description | Select-Object Name,Description

Name        Description
----        -----------
ENGG-PRO    Zone-1 ENGG WorkStation
OPER-01     Zone-1 OPER Machine
OPER-2      Zone-2 OPER Machine
OPER-3      Zone-3 OPER Machine
CORP-IT-E12


PS C:\>

使用过滤器按描述获取广告计算机

Get-AdComputer Filter 参数 使用 PowerShell 表达式语言为 Active Directory 编写查询字符串并搜索 Active Directory 中的计算机。

Get-AdComputer -Filter 'Description -like "Zone-1*"'  -Properties * | Select-Object Name,Description

在上面的PowerShell脚本中,Get-AdComputer Filter参数使用查询字符串通过Zone-1*等描述来搜索广告计算机,这意味着描述带有Zone-1星号。

它返回广告计算机的列表,其中描述类似于脚本中提供的查询。

[玩转系统] 使用 PowerShell 获取 AD 计算机描述

查找描述为空的 AdComputer

使用 Get-AdComputer Filter 参数,我们可以获得描述为空的 adcomputer。

Get-AdComputer -Filter {-not(Description -like "*") } -Properties Name, Description | Select Name,Description

在上面的脚本中,过滤器参数检查广告计算机描述是否为空,并选择广告计算机的名称和描述。

上述获取 adcomputer 的脚本的输出(描述为空)为:

PS C:\> Get-AdComputer -Filter {-not(Description -like "*") } -Properties Name, Description | Select Name,Description

Name        Description
----        -----------
CORP-IT-E12

从 OU 获取 AD 计算机描述

使用 Get-AdComputer SearchBase 参数,它可以搜索指定 OU 内的广告计算机对象并获取计算机的描述。

 $OUPath = 'OU=SALES,DC=SHELLPRO,DC=LOCAL'
 Get-ADComputer -Filter * -SearchBase $OUPath -Properties * | Select Name, Description | Export-CSV -Path C:\PowerShell\adcomputers-description.csv -NoTypeInformation

在上面的 PowerShell 脚本中,$OUPath 变量包含组织单位路径。

Get-AdComputer 使用 SearchBase 参数搜索指定 OUpath 内的计算机对象并获取带有描述的广告计算机。

PowerShell 中的 Export-CSV cmdlet 将广告计算机列表及其名称和说明导出到 CSV 文件。

ADUC - 获取 AD 计算机的描述

Active Directory 用户和计算机 控制台管理单元 GUI 工具提供了一个用户界面,用于在 Active Directory 中搜索计算机并获取广告计算机的描述。

要使用 ADUC 获取广告计算机的描述,请按照以下步骤操作:

  • 打开 ADUC 控制台管理单元(在“运行”中使用命令 dsa.msc)。
  • 转到操作菜单,然后单击查找菜单。
  • 它将打开查找对话框窗口来查找广告对象,例如用户、计算机等......
  • 在第一个下拉列表中选择计算机
  • 选择域或组织单位以限制搜索以查找计算机。
  • 输入计算机名称,然后单击立即查找按钮
  • 它将显示计算机名称列表。

[玩转系统] 使用 PowerShell 获取 AD 计算机描述

  • 双击列表中的计算机名称。它将打开 AD 计算机属性对话框
  • 检查广告计算机描述字段

[玩转系统] 使用 PowerShell 获取 AD 计算机描述

结论

我希望上面关于如何获取广告计算机描述以及使用 PowerShell 中的 Get-AdComputer cmdlet 获取 AD 计算机的描述的文章对您有所帮助。

您还可以使用 ADUC 查找 AD 计算机并检查“描述”字段,但当您必须获取一台计算机的描述时,它会很有用。要获取多个广告计算机的描述,请使用 Get-Adcomputer cmdlet。

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

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

取消回复欢迎 发表评论:

关灯