Skip to content

Instantly share code, notes, and snippets.

@NeilHanlon
Created April 18, 2014 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeilHanlon/11064226 to your computer and use it in GitHub Desktop.
Save NeilHanlon/11064226 to your computer and use it in GitHub Desktop.
$list = ipcsv '.\2014respond.csv';
#$list | ForEach-Object { Write-Host ($_.LastName)($_.FirstName.Substring(0,1)) }
$process = ForEach ($user in $list)
{
$user3 = $user.LastName +""+ $user.FirstName.Substring(0,1)
try{
$user2 = Get-ADUser $user3 -Properties mail
}
catch{
$user2.mail = "ERROR"
}
[PSCustomObject]@{RespondantID=$user.RespondentID;FirstName=$user.FirstName;LastName=$user.LastName;Email=$user2.mail}
}
$process | export-csv -Path '.\emails.csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment