I am trying to read information from a csv file that and use it to add phone numbers to our active directory if the email address is found in the csv file. (I know the EmailAddress attribute is not realiable, but it's all I have to work with based on where this data is being exported from). I have a powershell script of:
Import-Module ActiveDirectory
$csv = Import-Csv c:\users\user1\Desktop\userphones2.csv
foreach ($line in $csv) {
Get-ADUser -Filter {EmailAddress -eq $line.email} |
Set-ADUser -OfficePhone $line.phone
}
When I run this, for each record in the data file I get an error of
Get-ADUser : Property 'email' not found in object of type: 'System.Management.Automation.PSCustomObject'
CSV file is structured this way:
#TYPE System.Data.DataRow
"email","phone"
"user@example.com","8885555555"
"user2@example.com","8885555552"
If I do a Write-Output in the foreach loop instead of trying to get the data, this works. I have found many different syntaxes describing how to put a variable in a line like this for these filters, but nothing has worked. How do I get this filter to work?