【发布时间】:2019-11-06 21:36:08
【问题描述】:
如何将 Active Directory 数据(电子邮件地址和电话号码)导出到单个 CSV 文件中?
我已将 Active Directory 数据导出到数组并将数组导出到 CSV 文件,但 CSV 文件显示为空
# Change directory to where the CSV files are located
cd "C:\Users\srobins\OneDrive - Ruralco Holdings Limited\Desktop"
# Declare an array and assign the list of users to this
$users = Get-Content users.csv
# Create an array for the active directory data to be stored
$displayname = @()
# Loop through the list of users
foreach ($user in $users) {
# Get the active directory data and store in a tempory variable
$displaynamedetails = Get-ADUser -LDAPFilter { DisplayName -eq $name }| Select name,samAccountName,OfficePhone
# Append the active direcotry data into the array
$displayname += $displaynamedetails
}
#export the array containing the list of active directory data into the new CSV
$displayname | Export-Csv "C:\SamAccountName.csv" -NoTypeInformation
我希望创建 CSV 文件“SamAccountName”,并将 Active Directory 数据列表存储在其中。
CSV 文件正在创建,但它是空的。
【问题讨论】:
-
尝试将
$name更改为$user。 -
谢谢德鲁,真不敢相信我错过了这么愚蠢的事情!不幸的是,这并没有帮助 CSV 导出仍然为空
标签: arrays powershell csv active-directory