1.        创建一个powershell,并用管理员身份运行

# 导出员工信息到CSV文件

$exportPath = "D:\Path\Employees.csv"

# 获取"China" OU下的员工信息

$employeeInfo = Get-ADUser -Filter * -SearchBase "OU=China,DC=example,DC=com" -Properties DisplayName, EmailAddress, Manager, whenCreated | Select-Object DisplayName, EmailAddress, @{Name="ManagerEmail";Expression={(Get-ADUser $_.Manager -Properties EmailAddress).EmailAddress}},@{Name="whenCreated";Expression={$_.whenCreated.ToString("yyyy-MM-dd HH:mm:ss")}}

# 导出数据到CSV文件

$employeeInfo | Export-Csv -Path $exportPath -NoTypeInformation -Encoding UTF8

注释说明:

  1. $exportPath = "D:\Path\Employees.csv"设置导出文件的路径
  2. -Filter *:使用通配符过滤器,获取所有用户对象。
  3. -SearchBase "OU=China,DC=example,DC=com"设置搜索指定的OU路径
  4. -Properties DisplayName, EmailAddress, Manager, whenCreated:指定要获取的属性,包括显示名称、邮箱地址、领导信息和账号创建日期。
  5. Export-Csv:将员工信息导出到CSV文件。
  • -Path $exportPath:指定CSV文件的保存路径。
  • -NoTypeInformation:不包含类型信息行。
  • -Encoding UTF8:使用UTF-8编码保存CSV文件。

2.        查看生成的CSV文件