Share via


The search filter cannot be recognized

Question

Thursday, July 26, 2018 8:59 AM

Hi,

I'm importing a csv file to update users. It has the following headers:

UserPrincipalName;phonenumber;mobilephone;title;description;country;office;postalcode;streetaddress;city

$users = Import-CSV "C:\Tmp\ADUserUpdate.csv"foreach ($user in $users) {Get-ADUser -Filter "UserPrincipalName -eq '$($user.UserPrincipalName)'" -Properties * -SearchBase "DC=Domain,DC=local"| Set-ADUser -OfficePhone $user.PhoneNumber -Mobilephone $user.mobilephone -title $user.title -description $user.description -Country $user.country -Office $user.Office -PostalCode $user.PostalCode -streetaddress $user.Streetaddress -city $user.city}

I get the following error when I try to run the script:

The search filter cannot be recognized

In line:2 Char:28

  • foreach ($user in $users) {Get-ADUser -Filter "UserPrincipalName -eq '$($user.Us ...

    + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Does anyone know where I'm going wrong?

Thanks

All replies (3)

Thursday, July 26, 2018 9:22 AM ✅Answered

Hi,

I'm importing a csv file to update users. It has the following headers:

I get the following error when I try to run the script:

The search filter cannot be recognized

In line:2 Char:28

  • foreach ($user in $users) {Get-ADUser -Filter "UserPrincipalName -eq '$($user.Us ...

    + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Does anyone know where I'm going wrong?

Thanks

The error indicates blank entries or a corrupt CSV file.  Your "Import-Csv neds to use "-Delimiter ';'

\(ツ)_/


Thursday, July 26, 2018 9:03 AM

Please fix you code. It is posted all on one line and is unreadable and cannot be copied.

\(ツ)_/


Thursday, July 26, 2018 9:52 AM

Seems to do the trick. Thanks.