locked
The search filter cannot be recognized RRS feed

  • Question

  • 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


    • Edited by Noellawlor Thursday, July 26, 2018 9:14 AM
    Thursday, July 26, 2018 8:59 AM

Answers

  • 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:22 AM

All replies

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


    \_(ツ)_/

    Thursday, July 26, 2018 9:03 AM
  • 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:22 AM
  • Seems to do the trick. Thanks. 
    Thursday, July 26, 2018 9:52 AM