【问题标题】:Pulling AD user data not working on telephone/employeeID PowerShell在电话/employeeID PowerShell 上提取 AD 用户数据不起作用
【发布时间】:2019-03-01 08:31:46
【问题描述】:

此脚本未按预期提取广告用户数据。此代码正确提取名称和 UserPrincipalName,但其余字段为空白。我知道我提取的字段不是空白。结果应该是显示选择对象的 csv 文件。我错过了什么吗?我也没有收到错误消息。

$OUpath = 'ou=*****,OU=****,DC=****,DC=****,DC=****,DC=****'
$ExportPath = 'c:\scripts\users_in_ou2.csv'
Get-ADUser -Filter * -SearchBase $OUpath | 
Select-object Name,UserPrincipalName,mobile,mail,telephoneNumber,employeeID | 
Export-Csv -NoType $ExportPath

【问题讨论】:

    标签: excel powershell active-directory


    【解决方案1】:

    您需要告诉 get-aduser 您想要哪些属性。也可能有更好的方法,但这应该会得到你想要的结果

    $OUpath = 'ou=*****,OU=****,DC=****,DC=****,DC=****,DC=****'
    $ExportPath = 'c:\scripts\users_in_ou2.csv'
    Get-ADUser -Filter * -SearchBase $OUpath -Properties Name,UserPrincipalName,Mobile,EmailAddress,telephoneNumber,employeeID | 
    Select-object Name,UserPrincipalName,Mobile,EmailAddress,telephoneNumber,employeeID | 
    Export-Csv -NoType $ExportPath
    

    【讨论】:

    • 你一针见血。谢谢你。我很好奇为什么它允许 Name 和 UserPrincipalName 出现在我的原始代码中而不是其他字段中。
    • 默认情况下,Get-ADUser 将显示DistinguishedName、Enabled、GivenName、Name、ObjectClass、ObjectGUID、SamAccountName、@987654303 Surname 和 UserPrincipleName。所有其他属性都需要通过 -properties 参数明确请求
    猜你喜欢
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2016-01-29
    相关资源
    最近更新 更多