1

我有一个 CSV 文件,其中包含我域中的 PC 列表。我想从 AD 中获取 AD 中列出的每台机器的“描述”字段信息。这是我到目前为止所拥有的:

Import-Module ActiveDirectory

Get-ADComputer -Filter {OperatingSystem -NotLike "*Server*"} -SearchBase "OU=Active,OU=Regular Computers,OU=EPComputers,DC=epenergy,DC=net" -Properties * | Select-Object Name,OperatingSystem,CanonicalName | Export-Csv C:\PCList.csv -NoTypeInformation

我不确定我需要在哪里添加 get-ADObject 并过滤掉描述字段,甚至从哪里开始。任何帮助都是极好的!

谢谢你!

4

1 回答 1

1

您目前只向 CVS 输出以下属性:Name、OperatingSystem、CanonicalName。如果您将描述添加到您正在选择的对象列表中,您还应该获得描述属性。

Select-Object Name,OperatingSystem,CanonicalName,Description

这将使您的代码块:

Import-Module ActiveDirectory

Get-ADComputer -Filter {OperatingSystem -NotLike "*Server*"} -SearchBase "OU=Active,OU=Regular Computers,OU=EPComputers,DC=epenergy,DC=net" -Properties * | Select-Object Name,OperatingSystem,CanonicalName,Description | Export-Csv C:\PCList.csv -NoTypeInformation

我使用以下内容进行了测试,它返回了我域中所有机器的名称、描述、操作系统和 CanonicalName:

Import-Module ActiveDirectory

Get-ADComputer -Filter * -Properties * | Select-object name,Description,OperatingSystem,CanonicalName | Export-Csv C:\PCList.csv -NoTypeInformation

您可能会发现这个网站很有用,我几乎总能在 ss64 上找到我的 powershell 问题的答案

于 2016-03-29T18:56:00.717 回答