At the end of this project, I am trying to use a CSV file to update users personal details within AD. I plan to use Get-ADUser piped into Set-ADUser
My current problem is returning the user records from AD using Get-ADUser
My CSV file is as follows
FirstName,LastName,DisplayName,CompanyName,EmailAddress
John,Doe,John Doe,Test Company,[email protected]
Jane,Doe,Jane Doe,Test Company,[email protected]
My PowerShell script looks like this
Import-Csv .\Users.csv | ForEach {
Write-Host $_.EmailAddress
Write-Host $_.DisplayName
"`"$($_.EmailAddress)`""
Get-ADUser -Filter { userPrincipalName -eq "`"$($_.EmailAddress)`""}
}
What is returned is
[email protected]
John Doe
"[email protected]"
[email protected]
Jane Doe
"[email protected]"
Running Get-ADUser without using variables like below, returns the user account as it should, whereas the above code does not.
Get-ADUser -Filter { userPrincipalName -eq "[email protected]"}
Where am I going wrong?