【发布时间】:2019-02-27 01:20:10
【问题描述】:
我想获取电子邮件地址的 csv 并查找与这些地址匹配的用户。输出应该是找到的用户信息,或者如果找不到匹配的用户,则将搜索到的电子邮件地址放在一行中,然后是“未找到”
$base_path = "C:\scripts\validate_users\"
$source_file = "input_emails.csv"
$out_file = "results.csv"
#read the file, look them up
$users = Import-csv -Path ($base_path + $source_file) -delimiter ";" | ForEach {
try {
Get-ADUser -Filter "EmailAddress -eq '$($_.email)'" -Properties EmailAddress
}
catch {
"No user for" + '$_.email'
}
}
# Output the resultant collection to a csv file
$users | Export-csv -Path ($base_path + $out_file)
这给了我所有找到的记录并且没有错误消息。
我想避免将 $users 放入一个数组并在那里添加一个值。有没有办法在我现在得到的结果中添加内嵌“searchedforuser@fakedomain.com NOT FOUND”。
输入类似于
joesmith@ourdomain.com
janejones@ourdomain.com
freddielee@ourdomain.com
guywhoquit@ourdomain.com <== won't find this one
realuser@ourdomain.com
现在输出只是找到的四个用户的结果,没有迹象表明“guywhoquit@ourdomain.com”曾经在原始列表中
对不起,如果这是一个新手问题。我是一个ps新手,但是我搜索了很多,如果已经回答了类似的问题,我就错过了。
【问题讨论】: