ADScripts/Add-EmailToCSV.ps1
2023-09-14 11:13:58 -06:00

17 lines
469 B
PowerShell

# imports emails into CSV from a CSV containing DisplayName
$CSVFile = 'C:\Users\eeckert\Downloads\MS Project.csv'
$csvdata = Import-Csv $CSVFile
foreach ($item in $csvdata) {
$dname = $item.'Computer Current User Display Name'
$Filter = "DisplayName -eq '$dname'"
try {$item.Email = (Get-ADUser -Filter $Filter -Properties mail).mail}
catch {$item.email = 'lookup Failed'}
}
# $emails = $csvdata.Email
$csvdata | Export-Csv -Path $CSVFile