【问题标题】:Powershell Active Directory script to export csv with specific information/attributes用于导出具有特定信息/属性的 csv 的 Powershell Active Directory 脚本
【发布时间】:2020-08-07 03:44:08
【问题描述】:

我需要从活动目录中导出一些信息。 当前的 powershell 脚本成功获取了它要求的所有信息,但我还想获取用户属性“描述”或“公司”。

$OUpath = 'OU=OU,DC=DC'
$ExportPath = 'C:\path\users_in_ou7.csv'
Get-ADUser -Filter * -SearchBase $OUpath | Select-object GivenName, Surname,Name,UserPrincipalName | Export-Csv -NoType $ExportPath

当我将其中任何一个添加到 Select-object 部分时,我的 CSV 中会显示为空白。 例如:

Select-object Description, Company, GivenName, Surname, Name, UserPrincipalName

列标题已插入 CSV,但值为空白。这些属性填充在 AD 中的每个用户属性中。我不确定我是否在脚本中正确调用它们。任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: powershell active-directory


    【解决方案1】:

    使用Get-ADUser cmdlet 的-Properties 参数。

    来自Get-ADUserdocumentation

    此 cmdlet 检索一组默认的用户对象属性。要检索其他属性,请使用 Properties 参数。

    将此参数的属性指定为以逗号分隔的名称列表。要显示对象上设置的所有属性,请指定 *(星号)。

    【讨论】:

      【解决方案2】:

      您将-properties * 添加到查询中以提取所有属性。

      Get-ADUser -Filter * -SearchBase $OUpath -properties * | Select-object Description,GivenName, Surname,Name,UserPrincipalName | Export-Csv -NoType $ExportPath
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-16
        • 1970-01-01
        相关资源
        最近更新 更多