Hi Rising Flight,
你需要的是从某个 OU 及其所有子 OU 中导出用户信息,同时排除计算机对象,并保存到 CSV 文件。PowerShell 是最佳工具,但语法要写得准确,才能保证数据完整。
操作步骤
先加载 Active Directory 模块:
powershell
Import-Module ActiveDirectory
查询 OU 和子 OU 中的用户并导出:
powershell
Get-ADUser -SearchBase "OU=OU1,DC=contoso,DC=com" -SearchScope Subtree -Filter * `
-Properties Enabled, sAMAccountName, UserPrincipalName, mail, employeeID, employeeType |
Select-Object Enabled, sAMAccountName, UserPrincipalName, mail, employeeID, employeeType, DistinguishedName |
Export-Csv "C:\ADUsers.csv" -NoTypeInformation -Encoding UTF8
小提示
- 如果只想要启用的用户,可以改成
-Filter {Enabled -eq $true}。
OU 名称解析可能比较复杂,直接保留 DistinguishedName 会更直观。
建议先在小范围 OU 测试,避免一次性导出过多数据。
总结 用 Get-ADUser 搭配 -SearchScope Subtree,选择所需属性并导出到 CSV,就能得到干净的用户清单,而不会包含计算机对象。
Domic Vo.