从Active Directory获取部门号

时间:2018-10-09 06:03:07

标签: active-directory powershell-v2.0

我想获得Active Directory属性中包含的所有详细信息,但是我没有获得部门号。

PowerShell脚本为:

$Properties =
@(
'EmployeeID',
'givenName',
'EmployeeType',
'Departmentnumber'
)

Get-ADUser "Learner" -Properties $Properties |
    select $Properties |
    Export-Csv C:\Users\Learner\Desktop\test.csv

输出为:

enter image description here

1 个答案:

答案 0 :(得分:0)

departmentNumber是一个多值属性,因此您需要将DepartmentNumber属性替换为自身的错误版本,例如像这样:

... |
    Select-Object $Properties |
    Select-Object -Include *, @{n='DepartmentNumber';e={$_.DepartmentNumber[0]}} -Exclude DepartmentNumber |
...

或类似这样:

... |
    Select-Object $Properties |
    Select-Object -Include *, @{n='DepartmentNumber';e={$_.DepartmentNumber -join ' '}} -Exclude DepartmentNumber |
...